I am using theme concept in iOS.I am changing the background of each
UIViewController for that i have used an UIImageView as background for all view controllers.Now on theme change i want to change the image but in this case other UIImageView in the view controller are also changed.So i want to know how can i change the particular image view using appearance proxy.
Code for changing the appearance using proxy
[[UIImageView appearanceWhenContainedIn:[UpdateProfile class], nil] setImage:image];
Related
When I set the background color of a UITabBar iOS automatically lightens this color since the default UITabBar is translucent.
But I would like to use a UITabBar which is NOT translucent. In iOS 12 and below I solved this by setting a background image of the desired color:
// Create an image from a given color using a custom extension
[[UITabBar appearance] setBackgroundImage:[UIImage colorImageWithColor:[UIColor redColor]]];
This works fine. However, I would like to use the new Dark Mode in iOS 13. Obviously this cannot be done when using a colored background image instead of a background color. Instead not without reacting manually to the appearance change to switch to another color image.
Using named colors would be way better IF it would be possible to tell iOS not to draw the `UITabBar translucent.
If I try to disable the translucent effect the UITabBar become all white instead of the specified color.
[[UITabBar appearance] setTranslucent:false];
How to solve this?
I managed to solve the problem using a custom UITabBar subclass.
When the app launches the dynamic color MyDynamicTabBarBG is set as non-translucent background by creating an image from this color
Changes between Normal and Dark Mode while the app is active are detected using traitCollectionDidChange. Than the dynamic color is simply re-applied by creating a new image.
Code:
#implementation MCTabBar
- (void)awakeFromNib {
[super awakeFromNib];
// Create a color image from a given color using a custom extension
[self setBackgroundImage:[UIImage colorImageWithColor:[UIColor colorNamed:#"MyDynamicTabBarBG"]]];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[self setBackgroundImage:[UIImage colorImageWithColor:[UIColor colorNamed:#"MyDynamicTabBarBG"]]];
}
#end
This works but is quite hacky. Is there really no more elegant solution?
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.
I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...
I have been looking around but couldn't find anything good about this.
I would like to customize the default UIRefeshControl with different loader, etc. So far I can only change tintColor & attributedTitle properties and most code I found are just basically creating a new "pulltorefresh" effect but what I want is to just use the UIRefreshControl and customize it a bit.
Is this possible?
You can't add different loader without accessing private APIs, but you can add background image:
UIImageView *rcImageView =
[[UIImageView alloc] initWithImage:
[UIImage imageNamed: #"refreshControl.png"]];
[self.refreshControl insertSubview:rcImageView atIndex:0];
assuming self is an instance of UITableViewController subclass.
Image size you need is 320x43px (#2x 640x86px), the middle area (approximately 35px) will be covered by the loader animation.
I show application logo there...
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