首页 > 代码库 > UILabel根据内容自动调整高度
UILabel根据内容自动调整高度
效果图:
代码:
- (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];}
UILabel根据内容自动调整高度
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。