is it possible to target only a view controller's root view when using UIAppearance? I would like to setBackgroundColor for all of my controllers from my app delegate, but want to target only the direct view on a view controller. Thanks.
To elaborate, each UIViewController subclass has its own UIView object you can call via its view property. That's the view you put any stuff on like UITableView, UITabBar, etc in storyboard. I want the proxy to only apply to that direct view, since everything in UIKit is pretty much a subclass of UIView.
The purpose for this is is to centralize control on my view controllers appearance. It's occurring to me that perhaps maybe I should just use subclass of UIViewController, but I guess it'd still be cool to have another place to do what I just described.
Unfortunately, you can't accomplish this using the appearance proxy. However, one solution if you are using swift and loading your view controllers from storyboards or nibs is to extend UIViewController and override awakeFromNib like so:
extension UIViewController {
open override func awakeFromNib() {
super.awakeFromNib()
view.backgroundColor = UIColor.blue
}
}
来源:https://stackoverflow.com/questions/24689538/set-appearance-proxy-for-view-controller-root-view