美文网首页
iOS sizeToFit使用

iOS sizeToFit使用

作者: 侠客行1024 | 来源:发表于2016-10-24 10:59 被阅读743次

1.

UILabel *timer = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

timer.backgroundColor = [UIColor redColor];

[self.view addSubview:timer];

结果:

2.增加sizeToFit

UILabel *timer = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

timer.backgroundColor = [UIColor redColor];

timer.text = @"1000你fdsaasfsddsaasfafdfdfdfasf";

[timer sizeToFit];

[self.view addSubview:timer];

3.增加 timer.numberOfLines = 0;

UILabel *timer = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

timer.backgroundColor = [UIColor redColor];

timer.text = @"1000你fdsaasfsddsaasfafdfdfdfasf";

timer.numberOfLines = 0;

[timer sizeToFit];

[self.view addSubview:timer];

结果

4.使用adjustsFontSizeToFitWidth让字体随着屏幕宽度变小而变小

UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(100,100,100,100)];myLabel.textColor = [UIColor redColor];

myLabel.text = @"jfdisajfiafiodsajfhsahfaguhik";

myLabel.adjustsFontSizeToFitWidth = YES;

myLabel.font = [UIFont systemFontOfSize:18.0];

[self.view addSubview:myLabel];

相关文章

网友评论

      本文标题:iOS sizeToFit使用

      本文链接:https://www.haomeiwen.com/subject/vvqluttx.html