CGRect frame = [string boundingRectWithSize:CGSizeMake(Wdth, 10000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:font] forKey:NSFontAttributeName] context:nil]; 计算字符串需要多高或多宽 计算高度时宽度固定 计算宽度时 高度固定示例代码如下
NSString *textContent = @"对方会考虑了对方开罚单时时刻烦大叔看到司法会计课件拉屎地方开了个客户肯定会来撒会快拉倒是";
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont fontWithName:@"Heiti SC" size:20];
label.text = textContent;
label.numberOfLines = 0;
CGRect frame =[textContent boundingRectWithSize:CGSizeMake( 200, MAXFLOAT ) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:label.font forKey:NSFontAttributeName] context:nil];
label.frame = CGRectMake(0,100,200,frame.size.height);
[self.view addSubview:label];
NSString *textContent = @"对方会考虑了对方开罚单时时刻烦大叔看到司法会计课件拉屎地方开了个客户肯定会来撒会快拉倒是";
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont fontWithName:@"Heiti SC" size:20];
label.text = textContent;
label.numberOfLines = 0;
CGRect frame =[textContent boundingRectWithSize:CGSizeMake( 200, MAXFLOAT ) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:label.font forKey:NSFontAttributeName] context:nil];
label.frame = CGRectMake(0,100,200,frame.size.height);
[self.view addSubview:label];
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货