How can I make text in a UILabel shrink font size

后端 未结 4 628
慢半拍i
慢半拍i 2021-02-03 22:45

If a UILabel contains too much text, how can I setup my label so that it shrinks font-sizes?

Here is how I am setting up my UILabel:

     descriptionLabe         


        
4条回答
  •  猫巷女王i
    2021-02-03 23:30

    descriptionLabel.adjustsFontSizeToFitWidth = YES;
    descriptionLabel.minimumFontSize = 10.0; //adjust to preference obviously
    

    The following example is tested and verified on iPhone Simulator 3.1.2:

    UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 0, 200, 30)];
    
    descriptionLabel.font = [UIFont systemFontOfSize:14.0];
    descriptionLabel.minimumFontSize = 10.0;
    descriptionLabel.adjustsFontSizeToFitWidth = YES;
    descriptionLabel.numberOfLines = 1;
    descriptionLabel.text = @"supercalifragilisticexpialidocious even thought he sound of it is something quite attrocious";
    

提交回复
热议问题