现在的位置: 首页 > 综合 > 正文

UILable使用

2018年01月11日 ⁄ 综合 ⁄ 共 2277字 ⁄ 字号 评论关闭

调整UILable里的字体大小以适合UILalbe的大小

UILabel* lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 280, 150, 40)];
lable.text = @"wMAFAFAFEFFFFEA12";
lable.font = [UIFont systemFontOfSize:22];
lable.numberOfLines = 1;
lable.adjustsFontSizeToFitWidth = YES;
lable.minimumFontSize = 1.0f;
[self.view addSubview:lable]; 


  1. //设置显示文字         

  2. scoreLabel.text = @"我是ad";         

  3.      

  4. //设置字体:粗体,正常的是 SystemFontOfSize,调用系统的字体配置         

  5. scoreLabel.font = [UIFont boldSystemFontOfSize:20];         

  6.     

  7. //设置文字颜色,可以有多种颜色可以选择    

  8. scoreLabel.textColor = [UIColor orangeColor];         

  9. scoreLabel.textColor = [UIColor purpleColor];         

  10.   

  11. //设置文字对齐位置,居左,居中,居右         

  12. scoreLabel.textAlignment = UITextAlignmentRight;         

  13. scoreLabel.textAlignment = UITextAlignmentCenter;         

  14.     

  15. //设置字体大小是否适应label宽度         

  16. scoreLabel.adjustsFontSizeToFitWidth = YES;         

  17.     

  18. //设置label的行数,这个可以根据上节的UITextView自适应高度         

  19. scoreLabel.numberOfLines = 2;         

  20.     

  21. //设置文本是否高亮和高亮时的颜色       

  22. scoreLabel.highlighted = YES;         

  23. scoreLabel.highlightedTextColor = [UIColor orangeColor];         

  24.     

  25. //设置阴影的颜色和阴影的偏移位置         

  26. scoreLabel.shadowColor = [UIColor redColor];         

  27. scoreLabel.shadowOffset = CGSizeMake(1.0,1.0);         

  28.     

  29. //设置是否能与用户进行交互         

  30. scoreLabel.userInteractionEnabled = YES;         

  31.   

  32. //设置label中的文字是否可变,默认值是YES         

  33. scoreLabel.enabled = NO;         

  34.     

  35. //设置文字过长时的显示格式         

  36. scoreLabel.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间  

  1. //  typedef enum {         

  2.  //     UILineBreakModeWordWrap = 0,         

  3.  //      UILineBreakModeCharacterWrap,         

  4.  //      UILineBreakModeClip,//截去多余部分         

  5.  //      UILineBreakModeHeadTruncation,//截去头部         

  6.  //      UILineBreakModeTailTruncation,//截去尾部         

  7.  //      UILineBreakModeMiddleTruncation,//截去中间         

  8.  //  } UILineBreakMode; 

//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为

scoreLabel.baselineAdjustment = UIBaselineAdjustmentNone; 

  1. //  typedef enum {         

  2. //      UIBaselineAdjustmentAlignBaselines,         

  3. //      UIBaselineAdjustmentAlignCenters,         

  4. //      UIBaselineAdjustmentNone,         

  5. //  } UIBaselineAdjustment;

  1. //设置背景色为透明  

  2. scoreLabel.backgroudColor=[UIColor clearColor];  

  1. UIColor *color = [UIColor colorWithRed:1.0f green:50.0f blue:0.0f alpha:1.0f];    

  2. scoreLabel.textColor = [UIColor color];    

抱歉!评论已关闭.