1、先创建个UILabel的分类
2、创建属性@property (nonatomic) NSString *verticalText;
3、- (NSString *)verticalText{
// 利用runtime添加属性
return objc_getAssociatedObject(self, @selector(verticalText));
}
4、- (void)setVerticalText:(NSString *)verticalText {
objc_setAssociatedObject(self, &verticalText, verticalText, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
NSMutableString *str = [[NSMutableString alloc] initWithString:verticalText];
NSInteger count = str.length;
for (int i = 1; i < count; i ++) {
[str insertString:@"\n" atIndex:i*2-1];
}
self.text = str;
self.numberOfLines = 0;
}