zoukankan      html  css  js  c++  java
  • iOS中默认样式修改-b

    项目中有大量的UITableView都需要显示sectionHeader。iOS中默认sessionHeader上的textLabel样式跟设计图不符。
    

    按照我们之前的解决方案,是在每个UITableviewController上注册sessionHeader,然后在tableView:viewForHeaderInSection:方法中重用它们,并且修改文本字体和颜色。这种方式会产生一定量的重复代码,并且不利于维护。谁知道客户会不会心血来潮让把文字改成红色……

    在这里我们打算使用+ (instancetype)appearance;方法对全局的UITableViewHeaderFooterView样式进行修改。首先尝试的代码是:

    [[UITableViewHeaderFooterView appearance].textLabel setFont:[UIFont systemFontOfSize:12]];

    发现并没有奏效,仔细阅读了一下文档发现这么一段话

    To customize the appearance of all instances of a class, send the relevant appearance modification messages to the appearance proxy for the class.

    字面上理解的应该是发送一个message到对象上,而上面的代码是对于对象的一个属性发送一个message。应该是这里的问题。

    继续阅读代码,发现另外两个方法

    + (instancetype)appearanceWhenContainedIn:(nullable Class <UIAppearanceContainer>)ContainerClass;
    
    + (instancetype)appearanceWhenContainedInInstancesOfClasses:(NSArray<Class <UIAppearanceContainer>> *)containerTypes;

    这两个方法分别对应ios9之前和之后 
    实现如下:

    #ifdef __IPHONE_9_0
        [[UILabel appearanceWhenContainedInInstancesOfClasses:@[[UITableViewHeaderFooterView class]]] setFont:[UIFont systemFontOfSize:12]];
    #else
        [[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class]] setFont:[UIFont systemFontOfSize:12]];
    #endif

    问题解决~

  • 相关阅读:
    uva10986 堆优化单源最短路径(pas)
    动态规划②——线性动态规划(背包)
    UVA567
    动态规划①——记忆化搜索
    网络号与主机号的区分与计算(转)
    故障处理-ORA-00376/ORA-01110
    Oracle的自动统计信息不收集直方图的信息
    Oracle 11g的Redo Log和Archive Log的分析方法
    SQL优化 1
    oracle 11g 通过在线重定义方式修改表结构
  • 原文地址:https://www.cnblogs.com/isItOk/p/5648313.html
Copyright © 2011-2022 走看看