0
我用以下代碼製作了可變尺寸UILabel
。
但我想將最大寬度設置爲label
。
你有什麼想法嗎?製作最大寬度的可變尺寸UILabel
- (void)viewDidLoad {
CGSize size = [self labelFrameWithString:@"test text"];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width. size.height];
label.text = @"test text";
}
- (CGSize)labelFrameWithString:(NSString *)string {
CGRect frame = [string boundingRectWithSize:CGSizeZero
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine)
attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName]
context:nil];
return frame.size;
}