set appearance proxy for view controller root view

耗尽温柔 提交于 2019-12-07 22:46:35

问题


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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!