ios 运行时特征,动态改变控件字体大小
需求:ex: 在不同尺寸的iPhone上面显示的字体大小不一样
https://github.com/rentzsch/jrswizzle
#import <UIKit/UIKit.h> @interface UILabel (Common) - (void) swizzSetFont: (UIFont *) font; @end #import "UILabel+Common.h" @implementation UILabel (Common) -(void)swizzSetFont:(UIFont *)font { //添加对手机尺寸的判断(省略) if ([self isMemberOfClass:[UILabel class]]) { //条件判断,只修改UILabel, 并且字体大小为33的 NSLog(@"font=%@",font); if (font == [UIFont systemFontOfSize:33]) { [self swizzSetFont:[UIFont systemFontOfSize:10]]; }
NSError * error = nil; [UILabel jr_swizzleMethod:@selector(swizzSetFont:) withMethod:@selector(setFont:) error: &error]; NSLog(@"error=%@",error);