一.效果圖
二.代碼
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //根據內容自動調整高度 NSString *str = @"公元前3000年,印度河流域的居民的數字使用就已經比較普遍,居民們采用了十進位制的計算法。"; UIFont *font = [UIFont systemFontOfSize:13]; CGSize size = CGSizeMake(200,2000); CGRect labelRect = [str boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName] context:nil]; //UILabel UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50,100, labelRect.size.width, labelRect.size.height)]; label.text = str; label.backgroundColor=[UIColor redColor]; label.font = [UIFont systemFontOfSize:13]; label.numberOfLines=0; [self.view addSubview: label];}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答