Does UIAppearance work outside of AppDelegate?
If you are using xib to create your view you should do the appearance customization within the AppDelegate since customization should be performed before creating any UIControl objects. You can customize it for different view controllers/ containers using appearanceWhenContainedIn
To customize the appearances for instances of a class contained within an instance of a container class, or instances in a hierarchy, use +appearanceWhenContainedIn: for the appropriate appearance proxy.
For example:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:myNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
Use ViewController class
[[UIStepper appearanceWhenContainedIn:[MainViewController class], nil]setTintColor:[UIColor redColor]];
[[UIStepper appearanceWhenContainedIn:[DetailViewController class], nil]setTintColor:[UIColor greenColor]];
If you are creating the controls programmatically, no matter customize just before creating the control
[[UIStepper appearance]setTintColor:[UIColor redColor]];
UIStepper *stepper = [[UIStepper alloc]init];
[self.view addSubview: stepper];
Reloading tab bar appearance
With iOS 13 you can override traitCollectionDidChange(_:)
in UITabBarController to make changes. See documentation.
Example:
class TabBarControllerViewController: UITabBarController {
...
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
self.tabBar.barTintColor = UIColor.red
self.tabBar.unselectedItemTintColor = UIColor.darkGray
self.tabBar.tintColor = UIColor.white
}
}
UIAppearance has no effect on Label text color
Referring to this, UIAppearance kind of doesn't really seem work with UILabel...
Since you're subclassing from UILabel, maybe it would make sense to set textcolor
property initWithFrame:
method on in your MessageLabel class?
Or another option, since you say these MessageLabel instances are used for UITableViewCell's background, maybe it would make sense to leave label's background clear and change background of cell itself, for example in tableView:willDisplayCell:forRowAtIndexPath:
method in tableView's delegate?
How to create a proxy protocol like UIAppearance
Just make the proxy a static object and access it through class-level methods, the same way you'd implement a singleton, e.g.
@implementation MyClass
+ (MyProxyObject *)proxy
{
static MyProxyObject *sharedProxy = nil;
if (sharedProxy == nil)
{
sharedProxy = [[MyProxyObject alloc] init];
}
return sharedProxy;
}
@end
Then for any property of your class, e.g. textColor, just have your class use the value in [[self class] proxy].textColor instead of storing its own value. E.g.
@interface MyClass : UIView
@property (nonatomic, strong) textColor
@end
@implementation MyClass
- (UIColor *)textColor
{
return textColor ?: [[self class] proxy].textColor
}
@end
If you need a way to refresh your onscreen views immediately whenever a property on the proxy is changed, you could do that by having the proxy broadcast an NSNotification in its textColor setter method, and have all the instances observe that notification and call setNeedsDisplay on themselves when they receive it.
Related Topics
Disabling Auto-Play in Full Screen on Ios
How to Change Status Bar Text Color in Ios
Adjust Uilabel Height Depending on the Text
Figure Out Size of Uilabel Based on String in Swift
How to Apply Gradient to Background View of iOS Swift App
How to Convert a Uiview to an Image
Swift Compiler Error: "Expression Too Complex" on a String Concatenation
How to Write a File to a Folder Located At Apple'S Files App in Swift
Why It Shows "Ld: Framework Not Found Bolts"
Save Generated Gif to Camera Roll
Determine Device (Iphone, Ipod Touch) With Ios
How to Apply a Perspective Transform to a Uiview
How to Change the Name of an iOS App