• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 层次结构中的 UIAppearance 实例

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:20:05 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

来自 Apple 关于 UIAppearance 的文档:

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.

In any given view hierarchy the outermost appearance proxy wins. Specificity (depth of the chain) is the tie-breaker.

In other words, the containment statement is treated as a partial ordering. Given a concrete ordering (actual subview hierarchy), we select the partial ordering that is the first unique match when reading the actual hierarchy from the window down.

有人可以举例说明可以指定层次结构的情况吗?

考虑我希望仅为特定 UITableViewController 子类的实例设置 UITableViewCells 样式的情况

[[UITableViewCell appearance] setTintColor:[UIColor whiteColor]];

但仅对于 SomeXYZTableViewController 的 实例之一,即对于 SomeXYZTableViewController 的两个不同实例,我想要不同的色调。

还有很多其他方法可以做到这一点,但我只是想知道这是否可能。



Best Answer-推荐答案


But only for one of the SomeXYZTableViewController's instances

这当然是可能的,但让我们采取一种更简单、更有可能的方法来做到这一点。你可以继承 UITableView。让我们调用子类 WhiteTableView。它什么也不做;它只是一个子类。您可以将其中一个 TableView 设为 WhiteTableView。

所以现在您可以指定表格 View 单元格应该具有白色色调,但前提是它们位于 WhiteTableView 内。

我在书中给出的例子——来自现实生活——是:

[[UIBarButtonItem appearance]
    setTintColor: [UIColor myGolden]];
[[UIBarButtonItem appearanceWhenContainedIn:
    [UIToolbar class], nil]
        setTintColor: [UIColor myPaler]];
[[UIBarButtonItem appearanceWhenContainedIn:
    [UIToolbar class], [DrillViewController class], nil]
        setTintColor: [UIColor myGolden]];

这意味着:

  1. 一般来说,条形按钮项目应该被染成金色。

  2. 但工具栏中的条形按钮项是一个异常(exception):它们应该更白。

  3. 但是 DrillViewController View 中工具栏中的条形按钮项是异常(exception):它们应该是金色的。

关于ios - 层次结构中的 UIAppearance 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30339513/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap