How do you change the title color and/or bar tint color in a SKStoreProductViewController?
I'm using the appearance API to set navigation bars to a dark color and the text to white. It changes the title color but not the bar tint color in my SKStoreProductViewController.
I don't think you can. At least not on iOS 7. On iOS 6 you can use the UIAppearance protocol and the SKSPVC will pick up the appearance you set on the UINavigationBar.
As noted on this thread, the SKSPVC is a remote view controller so it's inaccesible programmatically, meaning that you can't set it's appearance directly (or indirectly?).
Do the following to avoid the SKStoreProductViewController to take over a tintColor of value WHITE:
#define kCOLOR_NON_WHITE_COLOR [UIColor darkGrayColor]
// CHANGE ALL TINTING BEFORE WE CREATE An INSTANCE OF THIS BROKEN PIECE
[UIWindow appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIView appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UINavigationBar appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIBarButtonItem appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
// NOW CREATE THE THING
SKStoreProductViewController *controller = [[[SKStoreProductViewController alloc] init] autorelease];
This draws all the UIBarButtonItems and the UISegmentedControls in this controller in the defined color AFAIK and thus makes the controller more like your apps design.
IMPORTANT: Just do not forget(!!!) to change all the tinting back after you dismissed this controller, otherwise fresh created views in your app might take over the enforced tinting.
UPDATE: As you might already have found out the following to manipulate the appearance does not work:
[UINavigationBar appearanceWhenContainedIn:[SKStoreProductViewController class], nil]
This fix is for iOS 7 & 8 on iOS 6 you have different issues. =)
Related
My UIDatePicker's background is black (because the background for the whole screen is black probably), but I want white in the background for this UIDatePicker.
Is there any way to change the background color without subclassing it?
iOS 14 update
It looks that datePicker.backgroundColor doesn't work in iOS 14. It works. But you have to put it after preferredDatePickerStyle setting:
let picker = UIDatePicker()
if #available(iOS 13.4, *) {
picker.preferredDatePickerStyle = .wheels
}
picker.backgroundColor = .red
datePickerName.backgroundColor = [UIColor grayColor];
OBJECTIVE C
datePicker.backgroundColor = [UIColor greenColor]
SWIFT
DatePicker.backgroundColor = UIColor.blueColor()
DatePicker.setValue(UIColor.greenColor(), forKeyPath: "textColor")
DatePicker.setValue(0.8, forKeyPath: "alpha")
iOS 14 update
After iOS 14 setting background color this way
datePicker.backgroundColor = <# your bg color #>
doesn't work anymore.
So I'm using key value coding approach now:
datePicker.setValue(<# your bg color #> , forKey: "backgroundColor")
I had this same problem. I just created a UIView and put it behind the UIDatePicker
datePickerBackground = [[UIView alloc] initWithFrame:myDatePickerView.frame];
datePickerBackground.backgroundColor = [UIColor whiteColor];
[self.view insertSubview:datePickerBackground belowSubview:myDatePickerView];
I declared UIView *datePickerBackground; in my class. I reuse this same ViewController so I set datePickerBackground to nil on unLoad.
Simple follow these steps
First you set the delegate in your .h file like:
UIPickerViewDelegate, UIPickerViewDataSource
Then add that line where you created the datepicker
YourDatePicker = [[UIDatePicker alloc] init];
YourDatePicker.backgroundColor=[UIColor whiteColor];
In your case the color is white but you can change it to as you want.
Normally, I would say that UIDatePicker inherits from UIView and that you could set the background programatically via a line like yourDatePickerRef.backgroundColor = [UIColor whiteColor];, but it turns out that -- according to this related question -- UIDatePicker has a number of subviews inside of it, some of which are the backgrounds views.
It's these subviews that you need to set the background color to white (instead of clear or whatever it's currently set to).
Yes, it's a bit of a pain, but this makes UIDatePicker a potentially powerful object in terms of being able to customize the appearance of.
Why not add a plain UIView behind the picker. Set the view's background color to white. Give the view the same frame as the picker.
Note (based on your comment to Michael's answer):
Digging around the private subviews of a UIDatePicker is risky. It could break at any time. It is almost guaranteed that your solution will break for date pickers used on a device with a locale that doesn't use AM/PM since the picker will only have two components instead of three.
It seems like there is no Apple permitted way to change the color of a uiactivityviewcontroller. I am creating it in my iPad app like this:
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:#[#"test"] applicationActivities:nil];
shareOptions = [[UIPopoverController alloc] initWithContentViewController:activity];
[shareOptions presentPopoverFromBarButtonItem:actionBarButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
This currently presents the popover with a blueish background color. I have seen a black background color used so I know it is possible. Another developer mentioned to me he thought on the iPhone at least it appears to be determined by the status bar color (as setting the status bar color to black opaque in the info.plist made the activityview black). This did not seem to have an effect on the iPad version. Does anyone have any ideas/suggestions?
Thanks!
UPDATE:
Setting activity.view.backgroundColor yields a weird result where most of the view is the set color but the edges are still the original blue
That's mentioned on the WWDC 2012 Video : Session 200 - What's new in Cocoa Touch.
The blueish part is a default layover you can deactivate with
UIPopoverBackgroundView +(BOOL)wantsDefaultContentAppearance
The app I'm working on has a custom nab bar but supports iOS 4.2-iOS 5, so I need to set the UINavigationBar background and tint in this old school way in my app delegate.
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
self.tintColor = [UIColor colorWithRed:42.0/255.0
green:164.0/255.0
blue:182.0/255.0
alpha:1.0];
UIImage *img = [UIImage imageNamed:#"navbar_bg.png"];
[img drawInRect:CGRectMake(0.0, 0.0,
self.frame.size.width,
self.frame.size.height)];
}
#end
This works for the most part, but I noticed when the app is first starting, the UIBarButtonItems flash the default navigation bar color for a second before they correct themselves and change color to match the navigation bar. Interestingly, the navigation bar itself uses the background image correctly from the get-go.
To be clear, I'm using setBackgroundImage for UINavigationBar on iOS 5 devices which works as expected so the flash is only in iOS 4.
Anyone have any insight on why this would happen and/or how to fix it?
The bar button items are the wrong color? You can manually set their tint color in viewDidLoad: to the tint color
navigationBar.rightBarButtonItem.tintColor = [UIColor ...]
if you're using a nib file. Otherwise you can do the same thing in loadView: . Either way this code will get executed as part of the initial draw loop so you'll have the proper color without any flashing.
Also for future reference, it's technically incorrect to override a method inside a category. (The latest version of Xcode, 4.3, will give you a warning about this). You should either properly subclass UINavigationBar or do "method swizzling". But that's pretty tough so don't worry about it right now :)
If you call the class with the code referenced in viewDidLoad try moving it to awakeFromNib
I'm trying to make my app feel more customized with a shaded navigation bar. For all controllers that I create, I can change the color of the navbar using:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
So all of my controllers use black navigation bars. However, when such controller is viewed in the "...More" tabbar section, the tint reverts to blue.
How do I change the ...More navigation controller tint?
As a side note, how do I would I go about globally define the style that my app is using?
edit:
To save some work, I defined a custom MyColors class, and put these methods in it:
+(UIColor*)navBarColor;
+(UIColor*)toolBarColor;
+(UIColor*)lightFontColor;
+(UIColor*)darkFontColor;
+(UIColor*)transparentColor;
This will help me change the colors of a UITabBar in the future without having to go hunting through each UIViewController and changing the color by hand!
Thank you!
If you want to set a global color then use the new appearance proxy.
for example,
[[UINavigationBar appearance] setTintColor:myColor];
Any UIKit object that adopts the UIAppearence protocol can be set globally like this.
self.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
In my app I have a uisegmentedcontrol in the navigation bar, as the right button item.
the code:
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [UIColor colorWithRed:0.70 green:0.171 blue:0.1 alpha:1.0];
works in OS2 but not OS3...?
ade.
p.s. my base sdk is 3.0
Ok,
I had to do two things:
1) For views that always had the segmentedcontrol I had to set the tint color after adding the segmentedcontrol to the rightbarbuttonitem and move the code to viewDidAppear (I had it in ViewWillAppear)
2) For views that don't always have the segmentedcontrol it looked ugly using viewDidAppear as it sometimes was showing the segmentedcontrol and then removing it (when it shouldn't be shown at all). So I had to here use viewWillAppear but also set the item to nil in viewDidDisappear
ade.