iOS5 TabBar Fonts and Color - objective-c

I have customized the TabBar appearance such
UIImage *tabBackground = [[UIImage imageNamed:#"tab-bar-bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage: [UIImage imageNamed:#"activetab.png"]];
How do I define the custom fonts and the selected and unselected text colors?
Thanks,

[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
[UIFont fontWithName:#"font" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateHighlighted];

[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], UITextAttributeTextColor,
[UIFont fontWithName:#"ProximaNova-Semibold" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateHighlighted];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
[UIFont fontWithName:#"ProximaNova-Semibold" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];

The above answer is working for me.
But I think most people should change the
forState:UIControlStateHighlighted to forstate:UIControlStateSelected

Related

iOS 7: Tint color randomly changes after showing a popup

I'm encountering a very weird problem which is driving me crazy.
The problem is that sometimes (it doesn't always happen), after showing a popup, the bar buttons and any UISegmentedControl become red, while they should be white (see the pictures below).
Here is also the code (in the app delegate initialization method) with which I set the the tint color of my app:
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
shadow,NSShadowAttributeName,
[UIFont fontWithName:#"HelveticaNeue-Thin" size:18],
NSFontAttributeName,
nil]];
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
shadow,NSShadowAttributeName,
[UIFont fontWithName:#"HelveticaNeue-Thin" size:18],
NSFontAttributeName,
nil] forState:UIControlStateNormal];
if ([self.window respondsToSelector:#selector(setTintColor:)])
self.window.tintColor = [UIColor redColor];
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
Any idea of why this is happening? I think that if there was a problem in my code, navigation bar buttons and segmented controls would be red since the app was launched, not after a while. What do you guys think?
Thanks
Mind trying setting de background color to white? It seems to be this that is changed. If this corrects it then we have a starting point
[[UITabBar appearance] setBackgroundColor:[UIColor whiteColor];
try and reply.
The problem is gone after commenting the following two lines:
if ([self.window respondsToSelector:#selector(setTintColor:)])
self.window.tintColor = [UIColor redColor];

UINavigationBar change title text color and font size

I want to change navigation title's font and color..so, for that i've done this below code..but its not working...
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7")) {
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:#"MyFavoriteFont" size:20.0],
NSFontAttributeName,
nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
NSLog(#"setTitleTextAttributes");
}
why this code is not working?
Apply Attributes to Navigationcontroller instance.
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7")) {
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:#"MyFavoriteFont" size:20.0],
NSFontAttributeName,
nil];
[self.transitionNavController.navigationBar setTitleTextAttributes:navbarTitleTextAttributes];
}
Hope this helps...
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
#{
UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:#"ArialMT" size:18.0f]
}];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
else
{
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// Uncomment to change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Uncomment to assign a custom backgroung image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
// Uncomment to change the back indicator image
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#""]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#""]];
// Uncomment to change the font style of the title
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,shadow, NSShadowAttributeName,[UIFont fontWithName:#"ArialMT" size:18.0], NSFontAttributeName, nil]];
CGFloat verticalOffset = 0;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}

How to reduce font size of navigation bar title in iOS 7

My App has a view controller with a navigation controller on top. The navigation bar title is 'Forgot Password'. This title was shown without any line breaks in iOS 5 and 6. However when I run the same App in iOS 7, the navigation bar title is shown with dots at the end - 'Forgot Passw…' The only way to rectify this defect is to reduce the for size of the navigation bar title.
Could someone tell me how should I do is ? Is there any APIs in iOS 7 exclusively for this purpose. Is it possible to reduce the font size of navigation bar title for this view controller alone ? Any suggestions would be welcome. Thanks in advance.
UILabel *nav_titlelbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.navigationItem.titleView.frame.size.width,40)];
nav_titlelbl.text=#"Tests";
nav_titlelbl.textAlignment=NSTextAlignmentCenter;
UIFont *lblfont=[UIFont fontWithName:#"FontinSansCR-Bold" size:20];
[nav_titlelbl setFont:lblfont];
self.navigationItem.titleView=nav_titlelbl;
I used following code in my project and its work for me :
/* ios 7 Change */
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//self.edgesForExtendedLayout = UIRectEdgeNone;
//self.automaticallyAdjustsScrollViewInsets = NO;
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x4B678B)];
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:#"Helvetica Neue" size:21.0], NSFontAttributeName, nil]];
// self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
//[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
Below is the code that I am using in my own project(iOS 7)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// set the title text property, color, font, size and so on
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor WhiteColor],NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:#"your font" size:21.0], NSFontAttributeName, nil]];
return YES;
}
Since iOS7, I always do like following:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Helvetica-Bold" size:SIZE_YOU_LIKE],NSFontAttributeName,
nil]];
The Keyword UITextAttributeFont has been depressed from iOS7, you'd supposed to replace with
NSFontAttributeName.
Just set SIZE_YOU_LIKE a value you like~

Adding image to the segment controller

Prior to iOS 7 it was easy to add colored image to the segment controller, but now if I add image to it, only the image is visible with the default Tint color and not the actual color.
Does any one have idea about this, if so kindly help me out.
Thanx in advance.
Fix it with: imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal
UIImage *segmentImage = [UIImage imageNamed:#"Example"];
if ([UIImage instancesRespondToSelector:#selector(imageWithRenderingMode:)]) {
segmentImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
[self.control insertSegmentWithImage:segmentImage atIndex:i animated:NO];
This may help you
UIImage *segmentSelected = [[UIImage imageNamed:#"Off.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentUnselected = [[UIImage imageNamed:#"On.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentSelectedUnselected =
[UIImage imageNamed:#"dividerOn.png"];
UIImage *segUnselectedSelected =
[UIImage imageNamed:#"dividerOff.png"];
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected
forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
forLeftSegmentState:UIControlStateNormal // | UIControlStateHighlighted
rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
forLeftSegmentState:UIControlStateHighlighted
rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal //| UIControlStateHighlighted)
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateHighlighted
barMetrics:UIBarMetricsDefault];
UIFont *font = [UIFont systemFontOfSize:16.0f];
UIColor *textColor = [UIColor darkGrayColor];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
font, #"NSFontAttributeName",
textColor, #"NSForegroundColorAttributeName",
nil];
[[UISegmentedControl appearance] setTitleTextAttributes:attributes
forState:UIControlStateNormal];
simply change the segmentController tintcolor to UIColor clearColor, use style controlstyleborder
SegmentControl.backgroundColor= [UIColor clearColor];
[SegmentControl setTintColor:[UIColor clearColor]];

How to change the [more] button text color in UITabBar?

I follow this answer change the bar items text color to white,but I have 6 tabbar items,I can't get the system button [more] item and change the text color.
How to change this [more] button text color to white?
thx.
my code:
for (UITabBarItem* item in self.tabBar.items)
{
NSLog(#"title:%#",item.title); // only get my items
[item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"AmericanTypewriter" size:11.0f], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
}
have you tried this , it's work for me :
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor yellowColor], UITextAttributeTextColor,
[UIColor redColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
Or replace self.myTabBar with [UITabBarItem appearance]