如何实现label字体的竖直排列
首先给Label添加一个Category 在.h中给label 添加一个 NSString类型的属性 (vertivalText)
.m中实现get 和set 方法
- - (NSString *)verticalText
- {
- // 利用runtime 添加属性- (void)setVerticalText:(NSString *)verticalText
- return objc_getAssociatedObject(self, @selector(verticalText));
- }
- - (void)setVerticalText:(NSString *)verticalText
- {
- objc_setAssociatedObject(self, &verticalText, verticalText, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- NSMutableString *mutableString = [[NSMutableString alloc] initWithString:verticalText];
- NSInteger count = mutableString.length;
- for (int i = 1; i < count; i++) {
- [mutableString insertString:@"\n" atIndex:i * 2 - 1];
- }
- self.text = mutableString;
- self.numberOfLines = 0;
- }