UILabel详解

来源:互联网 发布:linux cdrom 编辑:程序博客网 时间:2024/06/06 04:26
  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.       
  29. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.     
  30. - (void)viewDidLoad {     
  31.     UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];     
  32.     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 80.0, 200.0, 50.0)];     
  33.     UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 140.0, 200.0, 50.0)];     
  34.     UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 200.0, 200.0, 50.0)];     
  35.     UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 260.0, 200.0, 50.0)];     
  36.     UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 320.0, 200.0, 50.0)];     
  37.     UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)];     
  38.          
  39.     //设置显示文字     
  40.     label1.text = @"label1";     
  41.     label2.text = @"label2";     
  42.     label3.text = @"label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--";     
  43.     label4.text = @"label4--label4--label4--label4--";     
  44.     label5.text = @"label5--label5--label5--label5--label5--label5--";     
  45.     label6.text = @"label6";     
  46.     label7.text = @"label7";     
  47.          
  48.     //设置字体     
  49.     label1.font = [UIFont boldSystemFontOfSize:20];     
  50.          
  51.     //设置文字颜色     
  52.     label1.textColor = [UIColor orangeColor];     
  53.     label2.textColor = [UIColor purpleColor];     
  54.          
  55.     //设置文字位置     
  56.     label1.textAlignment = UITextAlignmentRight;     
  57.     label2.textAlignment = UITextAlignmentCenter;     
  58.     //设置字体大小适应label宽度     
  59.     label4.adjustsFontSizeToFitWidth = YES;     
  60.          
  61.     //设置label的行数     
  62.     label5.numberOfLines = 2;     
  63.          
  64.     //设置高亮     
  65.     label6.highlighted = YES;     
  66.     label6.highlightedTextColor = [UIColor orangeColor];     
  67.          
  68.     //设置阴影     
  69.     label7.shadowColor = [UIColor redColor];     
  70.     label7.shadowOffset = CGSizeMake(1.0,1.0);     
  71.          
  72.     //设置是否能与用户进行交互     
  73.     label7.userInteractionEnabled = YES;     
  74.          
  75.     //设置label中的文字是否可变,默认值是YES     
  76.     label3.enabled = NO;     
  77.          
  78.     //设置文字过长时的显示格式     
  79.     label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间     
  80. //  typedef enum {     
  81. //      UILineBreakModeWordWrap = 0,     
  82. //      UILineBreakModeCharacterWrap,     
  83. //      UILineBreakModeClip,//截去多余部分     
  84. //      UILineBreakModeHeadTruncation,//截去头部     
  85. //      UILineBreakModeTailTruncation,//截去尾部     
  86. //      UILineBreakModeMiddleTruncation,//截去中间     
  87. //  } UILineBreakMode;     
  88.          
  89.     //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为     
  90.     label4.baselineAdjustment = UIBaselineAdjustmentNone;     
  91. //  typedef enum {     
  92. //      UIBaselineAdjustmentAlignBaselines,     
  93. //      UIBaselineAdjustmentAlignCenters,     
  94. //      UIBaselineAdjustmentNone,     
  95. //  } UIBaselineAdjustment; 
原创粉丝点击