UILabel 常用方法汇总

  1. #import "LabelTestViewController.h"
  2. @implementation LabelTestViewController
  3. /*
  4. Accessing the Text Attributes
  5. text property
  6. font property
  7. textColor property
  8. textAlignment property
  9. lineBreakMode property
  10. enabled property
  11. Sizing the Label’s Text
  12. adjustsFontSizeToFitWidth property
  13. baselineAdjustment property
  14. minimumFontSize property 无例
  15. numberOfLines property
  16. Managing Highlight Values
  17. highlightedTextColor property
  18. highlighted property
  19. Drawing a Shadow
  20. shadowColor property
  21. shadowOffset property
  22. Drawing and Positioning Overrides
  23. – textRectForBounds:limitedToNumberOfLines: 无例
  24. – drawTextInRect: 无例
  25. Setting and Getting Attributes
  26. userInteractionEnabled property
  27. */
  28. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  29. - (void)viewDidLoad {
  30. UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];
  31. UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 80.0, 200.0, 50.0)];
  32. UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 140.0, 200.0, 50.0)];
  33. UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 200.0, 200.0, 50.0)];
  34. UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 260.0, 200.0, 50.0)];
  35. UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 320.0, 200.0, 50.0)];
  36. UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)];
  37. //设置显示文字
  38. label1.text = @"label1";
  39. label2.text = @"label2";
  40. label3.text = @"label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--";
  41. label4.text = @"label4--label4--label4--label4--";
  42. label5.text = @"label5--label5--label5--label5--label5--label5--";
  43. label6.text = @"label6";
  44. label7.text = @"label7";
  45. //设置字体
  46. label1.font = [UIFont boldSystemFontOfSize:20];
  47. //设置文字颜色
  48. label1.textColor = [UIColor orangeColor];
  49. label2.textColor = [UIColor purpleColor];
  50. //设置文字位置
  51. label1.textAlignment = UITextAlignmentRight;
  52. label2.textAlignment = UITextAlignmentCenter;
  53. //设置字体大小适应label宽度
  54. label4.adjustsFontSizeToFitWidth = YES;
  55. //设置label的行数
  56. label5.numberOfLines = 2;
  57. //设置高亮
  58. label6.highlighted = YES;
  59. label6.highlightedTextColor = [UIColor orangeColor];
  60. //设置阴影
  61. label7.shadowColor = [UIColor redColor];
  62. label7.shadowOffset = CGSizeMake(1.0,1.0);
  63. //设置是否能与用户进行交互
  64. label7.userInteractionEnabled = YES;
  65. //设置label中的文字是否可变,默认值是YES
  66. label3.enabled = NO;
  67. //设置文字过长时的显示格式
  68. label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
  69. // typedef enum {
  70. // UILineBreakModeWordWrap = 0,
  71. // UILineBreakModeCharacterWrap,
  72. // UILineBreakModeClip,//截去多余部分
  73. // UILineBreakModeHeadTruncation,//截去头部
  74. // UILineBreakModeTailTruncation,//截去尾部
  75. // UILineBreakModeMiddleTruncation,//截去中间
  76. // } UILineBreakMode;
  77. //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为
  78. label4.baselineAdjustment = UIBaselineAdjustmentNone;
  79. // typedef enum {
  80. // UIBaselineAdjustmentAlignBaselines,
  81. // UIBaselineAdjustmentAlignCenters,
  82. // UIBaselineAdjustmentNone,
  83. // } UIBaselineAdjustment;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值