一.效果圖
二.代碼
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //根據(jù)內(nèi)容自動(dòng)調(diào)整高度 NSString *str = @"公元前3000年,印度河流域的居民的數(shù)字使用就已經(jīng)比較普遍,居民們采用了十進(jìn)位制的計(jì)算法。"; 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];}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選