anybody know how to have an additional overlay on top of the selected item ?
the background are done in app delegate.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navbar_bgrd.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
}
else {
//iOS 4.whatever and below
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
}
Selected
not Selected
Fixed with IOS 5, UIappearance function
//set the background of tab bar
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navbar_bgrd.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
//[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar_bgrd.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"navbaractive.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateSelected];
Related
I am working in a project and I need to implement tab bar controller in this. my tab bar background color is black and I used following code for this :
[[UITabBar appearance] setTintColor:[UIColor blackColor]];
UITabBarItem *tabBarItem1 = [tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBarController.tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBarController.tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBarController.tabBar.items objectAtIndex:3];
[ tabBarItem1 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)];
[ tabBarItem2 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)];
[ tabBarItem3 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)];
[ tabBarItem4 setImageInsets:UIEdgeInsetsMake(2,0,-2,0)];
tabBarItem1.title=#"Home";
tabBarItem2.title=#"Connect";
tabBarItem3.title=#"About";
tabBarItem4.title=#"Settings";
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:139.0/255.0 green:189.0/255.0 blue:208.0 alpha:255.0], UITextAttributeTextColor,
[UIFont fontWithName:#"Arial" size:0.0], UITextAttributeFont,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:#"Arial" size:0.0], UITextAttributeFont,
nil] forState:UIControlStateSelected];
[tabBarItem1 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:#"home_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:#"home_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem2 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:#"connect_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:#"connect_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem3 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:#"about_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:#"about_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
[tabBarItem4 setFinishedSelectedImage:[self imageWithImage:[UIImage imageNamed:#"settings_icon_selected.png"] scaledToSize:CGSizeMake(24, 18)] withFinishedUnselectedImage:[self imageWithImage:[UIImage imageNamed:#"settings_icon.png"] scaledToSize:CGSizeMake(24, 18)]];
self.tabBarController.tabBar.tintColor = [UIColor whiteColor];
>
which is working fine in ios7 but there is no reflection of this line in ios6. Is there any thing else that I need to implement or any thing I missed regarding tab bar property in ios6? Any help will be appreciated.
Well they changed a lot about colors in iOS 7. Read the human interface guidelines by Apple: https://developer.apple.com/library/ios/documentation/userexperience/conceptual/MobileHIG/index.html
And here is the code:
//check if this is not iOS 7
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
//your code above except last line
//Tint is background in iOS 6 but text color in iOS 7
self.tabBarController.tabBar.tintColor = [UIColor blackColor];
}else{
//your code above
}
How can I recreate the letterpress-like effect applied to the backbarbuttonitem in the notes app in ios 7? I tried the following:
NSShadow *textShadow = [[NSShadow alloc] init];
textShadow.shadowOffset = CGSizeMake(0.0, -1.0);
textShadow.shadowColor = [UIColor blackColor];
NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:#"Back" attributes:#{NSForegroundColorAttributeName : [UIColor orangeColor], NSShadowAttributeName : textShadow}];
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:attributedTitle style:UIBarButtonItemStylePlain target:nil action:nil];
But it says I can't use NSAttributedString in place of an NSString.
For iOS 5 and above, you can use the UIAppearance functionality to change the Text Color, Font, Tint Color etc of multiple UI Components like UITabBar, UIBarButton, etc.
for UIBarButtonItem, check the below two options.
Option1: For ANY UIBarButtonItem:
NSDictionary *aButtonAttribute = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor darkGrayColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:aButtonAttribute forState:UIControlStateNormal];
Option 2: For UIBarButtonItem of a UINavigationBar ONLY:
NSDictionary *aButtonAttribute = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor darkGrayColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:aButtonAttribute forState: UIControlStateNormal];
NOTE: You can add these lines (either of the 2 options) in the .m file of AppDelegate..
Ive added a segmented control to the header of a uitableview. this works fine. but for some reason i cannot make the segmented buttons (or at least just the first button) have a red background color. it just loads with the default silver.
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* NEWview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NEWview.backgroundColor = [UIColor colorWithRed:78.0/255.0f green:88.0/255.0f blue:74.0/255.0f alpha:1.0];
NSArray *itemArray = [NSArray arrayWithObjects: #"Organisations", #"Events", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(15, 5, 290, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
UIColor *newSelectedTintColor = [UIColor redColor];
[[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor];
[NEWview addSubview:segmentedControl];
return NEWview;
}
Any Ideas? Thanks in advance for any help..
Tint color for segmentedcontrol works only if segmented control is of bar style.
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor=[UIColor redColor];
Refer this link to changed background color of selected segment
U can also do is set title color slected and not selected like this:
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Arial" size:20.0],UITextAttributeFont,
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil];//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[segmentCtrl setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Arial" size:20.0],UITextAttributeFont,
[UIColor redColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] ;//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[segmentCtrl setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
I am using a little chunk of code like below to change the text attributes of my nav bar title app wide and it works great.
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Cochin-BoldItalic" size:0.0], UITextAttributeFont,
nil]];
But I want to be able to just as easily do this for UIBarButtonItem text as well but I can't figure it out as it doesn't share the same or similar methods it appears.
Edit
Tried this code, not making any changes to text:
[[UIBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Cochin-BoldItalic" size:12.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
You want to use the - (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state method of UIBarItem (UIBarButtonItem inherits from UIBarItem).
Check out the docs for more details: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarItem_Class/Reference/Reference.html#//apple_ref/occ/cl/UIBarItem
Try this:
//Suppose you have initialized barButton elsewhere`
[barButton setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Cochin-BoldItalic" size:12.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
This seems to work on iOS 7.1:
[[UIBarButtonItem appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont fontWithName:#"Resamitz" size:16.0]}
forState:UIControlStateNormal];
with iOS 5, there is UI Appearance, is it possible to remove the gradient easy way ?
i do this to customised my tabbar, what can be done to remove the gradient ?
thanks for reading
-(void)UIAppearances
{
//set the background of tab bar
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navbar_bgrd.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
//iOS 5
//[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar_bgrd.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:#"navbaractive.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateSelected];
//nav bar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Rokkitt" size:28.0],
UITextAttributeFont,
nil]];
}
else {
//iOS 4.whatever and below
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
}
UITabBar can either take an image and use its alpha channel (opacity) to build the selected/unselected images or take two processed images to use as is.
You'll have to provide the images yourself to the UITabBarItem with setFinishedSelectedImage:withFinishedUnselectedImage:. There's no other way to affect the processing it does to the images besides changing the color of the gradient with UITabBar's selectedImageTintColor appearance property.