您的位置:首页 > 其它

怎么在xib创建的视图里面动态修改字体

2016-07-21 11:17 281 查看
写个类目,重写方法,交换方法。

+ (void)load{  

    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));  

    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));  

    method_exchangeImplementations(imp, myImp);  

}  

  

- (id)myInitWithCoder:(NSCoder *)aDecode{  

  

    [self myInitWithCoder:aDecode];  

    if (self) {  

        // 部分不想改变字体的 把tag值设置成555跳过  

        if (self.titleLabel.tag != 555) {  

            CGFloat fontSize = self.titleLabel.font.pointSize;  

            self.titleLabel.font = [UIFont systemFontOfSize:fontSize * SizeScale];  

        }  

    }  

    return self;  

}  

+ (void)load{  

    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));  

    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));  

    method_exchangeImplementations(imp, myImp);  

}  

  

- (id)myInitWithCoder:(NSCoder *)aDecode{  

      

    [self myInitWithCoder:aDecode];  

    if (self) {  

        // 部分不想改变字体的 把tag值设置成555跳过  

        if (self.tag != 555) {  

            CGFloat fontSize = self.font.pointSize;  

            self.font = [UIFont systemFontOfSize:fontSize * SizeScale];  

        }  

    }  

    return self;  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: