方法一:

        UILabel *mindName = [[UILabel alloc]initWithFrame:kCR(0, 0, 25,40)];
        
        mindName.text = @"苏\n小\n明";
        mindName.numberOfLines = [mindName.text length];
    

方法二:

//        NSString *text = @"一";
//        NSString *strText = @"苏得强";
//        UIFont *font = [UIFont systemFontOfSize:12];
//        CGSize sizeWord = [text sizeWithFont:font constrainedToSize:CGSizeMake(320, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
//        CGFloat w = sizeWord.width;//一个汉字的宽度
//        CGSize sizeStr = [strText sizeWithFont:font constrainedToSize:CGSizeMake(w, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
//        CGFloat h = sizeStr.height;
//        
//        UILabel *aLabel = [[UILabel alloc]initWithFrame:kCR(0, 0, w, h)];
//        aLabel.text = strText;
//        aLabel.backgroundColor = [UIColor clearColor];
//        aLabel.textColor = [UIColor whiteColor];
//        aLabel.numberOfLines = 0;
//        [aView addSubview:aLabel];

 

相关文章:

  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-12-10
  • 2022-01-25
  • 2021-12-11
猜你喜欢
  • 2021-09-19
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-07-31
  • 2021-07-10
  • 2021-07-26
相关资源
相似解决方案