@interface UILabel (LeftTopAlign)- (void) te ">
iOS中默許的UILabel是垂直居中對齊的,如果UILabel設置的高度較大,當內容少的時候,會自動垂直居中。
創建1個 UILabel的category
代碼以下:
#import
在需要的時候,只需要直接調用便可。
#import "UILabel+LeftTopAlign.h"
@implementation UILabel (LeftTopAlign)
- (void) textLeftTopAlign
{
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12.f], NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [self.text boundingRectWithSize:CGSizeMake(207, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
CGRect dateFrame =CGRectMake(2, 140, CGRectGetWidth(self.frame)⑸, labelSize.height);
self.frame = dateFrame;
}
@end
上一篇 Java開發思路講解
下一篇 常用的oracle數據字典