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];