重写UILabler的sizeThatFits方法,需要触发两次才会有效果

#import "ViewController.h"
@interface SpecialLabel:UILabel
@end @implementation SpecialLabel - (CGSize)sizeThatFits:(CGSize)size { CGSize s = [super sizeThatFits:size]; return CGSizeMake(s.width +, s.height +);
}
@end @interface ViewController () @property (weak, nonatomic) IBOutlet SpecialLabel *label; @end @implementation ViewController - (IBAction)changeText { self.label.text = @"fsdgdssssssssssss ";
#if 1
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.label sizeToFit];
}];
#else
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.label sizeToFit];
});
#endif }
直接这样写不知道为什么不行
self.label.text = @"fsdgdssssssssssss ";
[self.label sizeToFit];

非得搞个

[NSOperationQueue mainQueue]或者延时,记录一下
 
上一篇:MYSQL导入中文数据乱码的四种解决办法


下一篇:C#水晶报表教程