本文纯属个人见解,是对前面学习的总结,如有描述不正确的地方还请高手指正~
UILabel * label = [[UILabel alloc] init];
NSString * text = @"hellohellohellohellohellohellohellohellohellohellohellohello ";
label.text = text;
[label setNumberOfLines:0];
UIFont *font = [UIFont fontWithName:@"Arial" size:14];
//设置字体
label.font = font;
CGSize size = CGSizeMake(300, 20000.0f);
size = [text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
[label setFrame:CGRectMake(10, 0, size.width, size.height)];
[label setFrame:CGRectMake(10, 0, 200, 100)];
[self.view addSubview:label];
这是网上的代码,可以正常运行。但还到遇一个题问,就是这里的label是态动生成的,如果对于view中一个拖出来的label然后在controller中连接一个对应的属性,这个label的setFrame一直效无,这时可以点到size inspector中,找到constraints中的height equals,点击前面的齿轮图案,选择select and edit,在height constraints中将Priority的值设置的小一些可即。
文章结束给大家分享下程序员的一些笑话语录: 看到有人回帖“不顶不是中国人”,他的本意是想让帖子沉了。