At this point in time I'd like to keep my code compatible with Xcode 4, therefore I don't want to upgrade my nib files.
However, I can't change the UISegmentedControl control tint colour and use the new iOS7 version of the control without upgrading the nib file.
I've seen ..
[NSUserDefaults standardUserDefaults] setObject:#Yes forKey#"UIUseLegacyUID"]
Which will keep iOS6 layout, I'm not sure if there is an future version or whether this would help?
With Xcode 5, you can change your XIB to use the property of Xcode 4 and iOS 6.
By default you have:
But, you can change the property for Xcode 4.6 and iOS 6:
You can change the tint color in the code like this:
UISegmentedControl *segmentedControl = ...;
// For backwards compatibility
if ([segmentedControl respondsToSelector:#selector(tintColor)])
{
segmentedControl.tintColor = [UIColor redColor];
}
You can set different segment image and color for each segment. For color you may use:
//get the subviews of the segmentedcontrol
NSArray *arri = [segmentedControl subviews];
//change the color of every subview(segment) you have
[[arri objectAtIndex:0] setTintColor:[UIColor redColor]];
[[arri objectAtIndex:1] setTintColor:[UIColor greenColor]];
Related
Image 1
Image 2
Image 3
1st image is the settings screen and everything behaves normally
upon the first loading of this screen.
2nd image is the policy
screen which is pushed from the settings screen.
3rd image upon returning from the policy screen back to the settings screen shows the UI Slider now doesn't show the track image. The behavior still works normally, but the track is just gone. It's a very mysterious bug to me. If I go to another screen in the app and then hit settings it works fine again, but when I come from the policy screen the track image is gone.
I am using the default UISlider. I am using xib files for the different screens.
When the Policy Button is clicked...
EditorialPolicyViewController *policyView;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
policyView = [[EditorialPolicyViewController alloc]initWithNibName:#"EditorialPolicyViewController_iPad" bundle:nil];
}
else
{
policyView = [[EditorialPolicyViewController alloc]initWithNibName:#"EditorialPolicyViewController_iPhone" bundle:nil];
}
[self.navigationController pushViewController:policyView animated:YES];
ViewDidLoad - setting up the uislider
NSString *textSize = [[NSUserDefaults standardUserDefaults] valueForKey:#"Text Size"];
float textSizeFloat = [textSize floatValue];
self.textSizeSlider.value = textSizeFloat;
[self.textSizeSlider setMaximumValue:16.0];
[self.textSizeSlider setMinimumValue:11.0];
Let me know if you have any other questions. I am out of ideas on how to solve this bug.
UPDATE
Found that the code below was "theming" the slider but when I removed it, it worked fine. What is a way i can keep the theme color and not get it to disappear?
[[UISlider appearance] setThumbTintColor:[UIColor colorWithRed:0/255.0f green:75/255.0f blue:152/255.0f alpha:1.0f]];
[[UISlider appearance] setMinimumTrackTintColor:[UIColor colorWithRed:164/255.0f green:75.0f blue:25/255.0f alpha:1.0f]];
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
This is the well known bug in SetMaximumTrackTintColor.
Remove this line:
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
and your app will work fine.
It is correct that this is a known bug. But have found a way to work around it so that you can still keep your theming:
[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
In UIViewController's where I use a slider, I set the maximumTrackTintColor in the viewDidLoad: method
- (void)viewDidLoad
{
[super viewDidLoad];
_slider.maximumTrackTintColor = [UISlider appearance].maximumTrackTintColor;
}
This works for me, so I wanted to share!
you can move the appearance changes into the viewDidLoad: function.
this way the appearance changes will only happened once.
- (void)viewDidLoad
{
// Appearance changes here
}
it works for me
I'm in the process of upgrading my app to iOS7. However I want to preserve the iOS6 interface as well. It works well except for the navigation bar(s). In iOS7 they look great (just the default color with the translucent property to YES. In iOS6 the navigation bars are showing as the default blue bars and I want them to be black translucent.
What I do is check the version of the iOS and then perform some code. In the debugger I see they right version in the vComp variable but the color is not changing. Don't mind the redColor property, that's just for the test. In both ways I am presented with the default color.
Here is my code:
- (void) fixNavBarColor:(UINavigationBar*)bar {
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:#"."];
if ([[vComp objectAtIndex:0] intValue] >= 7) {
bar.barTintColor = [UIColor redColor];
bar.translucent = NO;
}
else {
bar.tintColor = [UIColor redColor];
bar.opaque = YES;
}
}
There is no error or warning.
Any ideas?
You shouldn't set the tintColor straight to navigationBar as it wouldn't be applied to other parts of your app, you should instead use UINavigationBar's appearance to set tintColor which is available on iOS 5.0 onwards.
[[UINavigationBar appearance] setTintColor:"Your Color"];
Use this code for iOS6
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:.8]]
forBarMetrics:UIBarMetricsDefault];
[[UITabBar appearance] setTintColor:[UIColor redColor]]; // for unselected items that are red
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]; // for selected items that are green
Why is this code not working in iOS 7?
setTintColor works but only changes the "selected"-icon's color, not the unselected ones as it did in earlier iOS versions, which is weird ? setSelectedImageTintColor does'nt work at all anymore ? Is it realy not possible to color icons as you wish anymore?
Also the setSelectionIndicatorImage is not working as intended in the start of the app, what is happening in iOS 7?
Derp herp Apple, why ?
As of iOS 7 you have to use setBarTintColor: to set the background color, with setTintColor: now affecting the foreground color.
Answer from Adam Waite doesn't work. Method setFinishedSelectedImage under iOS7 ignores the selected image. You need to so it like this:
UITabBarItem *item1 = _tabBarController.tabBar.items[0];
item1.image = [[UIImage imageNamed:#"item1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item1.selectedImage = [UIImage imageNamed:#"item1-selected"];
It's not tint, but you can do it with images:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"item_seleted.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"item_unselected.png"]];
This is a known issue in iOS 7. The tintColor is used for the selected tab image. The selectedImageTintColor is completely ignored. There is no way to tint unselected tab images.
See a discussion on the Apple Developer Forums https://devforums.apple.com/message/851126#851126 about this.
for (int i=0; i (smallerthen)arrayOfTabBarItems.count; i++) {
NSString *unselectedImageName = [NSString stringWithFormat:#"%#.png", arrayOfTabBarItems[i]];
NSString *selectedImageName = [NSString stringWithFormat:#"%#-pressed.png", arrayOfTabBarItems[i]];
[tabBarCtrl.tabBar.items[i] setFinishedSelectedImage:[UIImage imageNamed:selectedImageName] withFinishedUnselectedImage:[UIImage imageNamed:unselectedImageName]];
}
This worked for me.
I need to make my grouped UITableView backgroundColor transparent.
So i write following code. That is work in iOS 6. But in iOS 5, it doesn't work.
self.tbView.backgroundView = nil;
How to do that in iOS 5.
Are you setting [self.tbView setBackgroundColor:[UIColor clearColor]];?
If not, you need to add that or you won't get a transparent backgorund color.
You Need to put background Nil code into ViewDidLoad this is working fine in my Code. Hope this Helps you.
[tbl_My_Table setBackgroundView:nil];
[tbl_My_Table setBackgroundView:[[[UIView alloc] init] autorelease]];
I got it answer.
We need to add two lines of codes for both iOS 6 and iOS 5.
Here is codes.
self.tblPreferences.backgroundView = nil;
self.myTable.backgroundColor = [UIColor clearColor];
That is working both iOS 5 and 6.
I am using UIButton's appearance proxy to customize all UIButtons in my application. Everything is working very well - I can set custom image, text color and shadow color. Only one thing is bugging me. To set shadow offset, I've used this piece of code:
[[UIButton appearance] setTitleShadowOffset:CGSizeMake(1, 1)];
And it's working. But the documentation says that setTitleShadowOffset: is deprecated, and instead we should use the shadowOffset property of the titleLabel. I've tried it like this:
[[[UIButton appearance] titleLabel] setShadowOffset:CGSizeMake (1.0, 1.0)];
but it's not working. Can I set shadow offset without using a deprecated method?
Try:
[[UILabel appearanceWhenContainedIn:[UIButton class], nil]
setShadowOffset:CGSizeMake(1.0, 1.0)];
([[UILabel appearance]
setShadowOffset:CGSizeMake(1.0, 1.0)]; should also work but is probably overkill as it will affect all UILabels, not just the ones contained in UIButtons.)