Change Tint/Background colour of iOS controls without using images - ios

Is it possible using the UIAppearance proxy (in iOS 5) to change the background colour of iOS Elements, specifically the tab bars and title bars without using images?
I'd like to use a deep green gradient, but without using images. Is it possible to do so in both iOS 5 and below?

Well you're asking two different questions here, but if you want to simply change the tint color it can be done like this...
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1];
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:255 green:0 blue:0 alpha:1];
Additionally, if you wish to use a gradient this is possible to do without imagery, but is best done with a tiled image...
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myGradient.png"]];
self.tabBarController.tabBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"myGradient.png"]];

Heh, now in iOS6 you can now add UIStatusBarTintParameters key to Info.plist.
From the iOS6 GM changelog:
It is now possible to set status bar tint parameters in your app's Info.plist file. You might do this to ensure that the status bar color matches your app’s navigation bar color during startup. To set the status bar tint, add the UIStatusBarTintParameters key to your Info.plist file. The value of this key is a dictionary with the appropriate values describing the navigation bar your app has at startup. Inside the dictionary should be the UINavigationBar key, which has a value that is also a dictionary. That dictionary contains the initial navigation bar’s style (with the Style key) and indicates whether it is translucent (with theTranslucent key). You can also specify your navigation bar’s tint color (with the TintColor key) or the name of its custom background image (with the BackgroundImage key).

Related

Apptentive Message cell color change

Hi I tried to customize apptentive
ApptentiveMessageCenterReplyCell, ApptentiveMessageCenterContextMessageCell, ApptentiveMessageCenterMessageCell color since it is being used as cell in Storyboard. On color change i want to update its background color for that i could not access it from styleSheet using SDK.
iOS SDK version: apptentive-ios 4.0.7
//Example code
ApptentiveStyleSheet *style = [[Apptentive sharedConnection]styleSheet];
style.backgroundColor = self.isLightTheme ? [UIColor whiteColor] : [UIColor blackColor];
style.primaryColor = self.isLightTheme ? [UIColor blackColor] : [UIColor whiteColor];
Facing issue in while changing color in iPhone X landscape. Could not able to change color for mentioned cells UITableViewCell..
Currently the stylesheet object doesn't fully support changing colors after Message Center or Surveys have launched for the first time.
However, when your app's theme changes, you should be able to set the didInheritColors boolean property to NO on the stylesheet object by e.g. using key-value coding.
This should cause the stylesheet to re-calculate the various intermediate colors that are determined from the primary and background colors (you'll probably want to avoid changing the theme while Message Center is being displayed, as it could cause inconsistent colors).
Another approach is to set an explicit color override on the stylesheet object using -setColor:forStyle:, but you would have to do this for both the directly-set colors and the intermediate ones that are calculated from those.

how to change ui componts color according to iOS theme?

I am very new to iOS.I want to set the theme for my iOS app & according to theme i am changing the background image.I also want to change the color of other ui component according to background image.I have one way of doing it by saving value in UserDefaults & check for every UI Component that would be very lengthy process.Is there any kind of other simple way of doing it in iOS?
You can take advantage of appearance proxy. Most of UIKit components have an appearance proxy object.
Let's take for example a navigation bar.
You can have this code.
UIColor *barColor = [UIColor redColor];
[[UINavigationBar appearance] setTintColor:barColor];
Once you execute this, all navigation bars across your app will have a red tint colour. You can customise other things and this way you set your theme globally.

How can i change the color of the predefined buttons in apple research kit

I am trying to make a survey using Apple's ResearchKit but I couldn't find how to change the color of the predefined buttons. They are blue but I want to make them of a different color. How to do this?
Using UIView's appearance proxy to set the tint color should work:
[UIView appearance].tintColor = yourColor;
It's very late now but might save somebody's time, worked for me:
taskviewcontrollerobject.view.tintColor = [UIColor redColor]; // color of your choice

How should I accomplish "setTintColor forState" (which does not exsist)?

In my app delegate I have this:
UIColor* color = [UIColor colorWithRed:36/255.0f green:38/255.0f blue:56/255.0f alpha:1.0f];
[[UIBarButtonItem appearance] setTintColor:color];
I'd like to have another color set for the pressed state.
How do I achieve this without using a background image?
The UIBarButtonItem don't have different states. However the UIButton do. So you might want to put an ordinary Button in your navigation bar or toolbar and then use different background images per state, which is possible for UIButton or you use the Highlight Tint property if you just want to change the tint for the highlighted state.
If you use an image for the different states, then you get to define an image for those states:
Default
Highlighted
Selected
Disabled
See this SO post: UIButton as UINavigationbar button

How to change UITabBar Selection color

I need to change the selection color of UITabBar from default blue to red. How do we do this.
Update September 2017:
It's been two years since I've written this answer and since it's receiving upvotes regularly, I should say this is probably the worst possible answer to this question, it's error prone, likely to break because of iOS updates, hard to debug, etc., so please don't do the things I've written and apply better solutions such as subclassing UITabBar or UITabBarController. Thanks.
You can do this by setting a "tintColor" attribute (Key Path) for you UITabBar.
Select the UITabBar in the document outline. (NOT the Controller with the yellow icon.)
Select Identity Inspector in the Utilities area.
Click the + in "User Defined Runtime Attributes."
Add a "tintColor" Key Path of type "Color" and the color you want.
This should do it. You can check it against the screenshot below.
More on this:
There's a "Tint" attribute in Identity Inspector of UITabBar which I believed would do the exact same thing but apparently, it does nothing. It's default value is the exact default fill color when a UITabBarItem is selected, so my guess is it would be fixed in the stable release Xcode 7. Fingers crossed.
In IOS5, UITabBar has a selectedImageTintColor property which does what you need.
In iOS 7 it's simply the tintColor. One way to accomplish this could be to subclass UITabBarViewController, set the custom class in the storyboard, and in your viewDidLoad method of the subclassed tabBarVC add this:
[[self tabBar] setTintColor:[UIColor redColor]];
To achieve above result perform following steps.
Step 1: Add your desired images in Assets.xcassets, and make sure they Render As: Default
Step 2: Select your UITabBar object and set Image Tint color, this color will be selected tab color
Step 3: Select UITabBar object and add Key Path: unselectedItemTintColor, Type: Color, Value: Choose color for unselected item in User Defined Runtime Attributes.
All done.
It is extremely easy
Create a custom class of UITabBarController and in -(void)viewDidLoad method add this line:
[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]];
Because UITextAttributeTextColor is deprecated in iOS 7, you should use:
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
Starting from iOS 8 it's as simple as:
UITabBar.appearance().tintColor = UIColor.redColor()
Simply change the following property in Interface Builder for the TabBar
Obviously in my case its White.
The SDK does not make this easy, but it is technically possible. Apple apparently believes this to be part of their vision of a consistent look and feel.
UITabBar is a subclass of UIView. You can always subclass and implement your own -drawRect:
This is not a trivial task, however, you have to essentially re-implement the class from scratch or you risk some weird side-effects.
Swift 5 Programatically
It is pretty easy in Swift 5.
In your TabBarController write this:
tintColor = UIColor.red
That's it
I've been searching for a way to set the selected text color of a UITabBarItem and have found a dead simple method, using the UIAppearance protocol.
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
Please excuse the awful colors!
iOS 5.0 fixes this issue but the solution is under NDA. Look up UITabBar in your documentation for an EASY way to do what you want to do.
I found the easiest solution -
Select Tab Bar in Tab Bar Controller
Set Image Tint color
Set Tint Color
For reference see the attached image.

Resources