set appearance proxy for view controller root view

2019-05-24 12:44发布

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.

1条回答
▲ chillily
2楼-- · 2019-05-24 13:45

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
    }
}
查看更多
登录 后发表回答