最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[整理]swift中关于UIAppearance的appearance()

Swift crifan 4011浏览 0评论
根据:
ios – Changing navigation bar color in Swift – Stack Overflow
的:
UINavigationBar.appearance().backgroundColor = UIColor.greenColor()
UIBarButtonItem.appearance().tintColor = UIColor.magentaColor()
UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]
UITabBar.appearance().backgroundColor = UIColor.yellowColor();
参考:
UIAppearance Protocol Reference
得知:
  • UINavigationBar
  • UIBarButtonItem
  • UINavigationBar
  • UITabBar
 都实现了UIAppearance这个协议
-》所以这些类,控件才有appearance()
-》然后可以通过这些类的appearance()去全局地设置各种颜色:背景色,文字图片的颜色等等
-》
官网的解释中都用此来举例了“For example, to modify the bar background tint color for all instances of UINavigationBar:”
举例:
且注意:
如果一个view已经显示在window中了,再去调用appearance()是没用的。

转载请注明:在路上 » [整理]swift中关于UIAppearance的appearance()

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.174 seconds, using 22.01MB memory