代码改变世界

UIlable

2015-11-09 20:42  1314256  阅读(178)  评论(0编辑  收藏  举报

Label用法总结
(1)初始化
UILabel *aLabel=[[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 50)];
(2)文字内容
//位置默认是靠左的
[aLabel setText:@"hello"];

//设置字体颜色
aLabel.textColor=[UIColor blueColor];
aLabel.textColor=[UIColor redColor];

//设置字体大小
aLabel.font=[UIFont systemFontOfSize:12.4];
//修改字体的字体和大小
aLabel.font=[UIFont fontWithName:@"Arial Rounded MT Bold" size:36.0];

//设置背景颜色
aLabel.backgroundColor=[UIColor redColor];
//清空背景颜色
aLabel.backgroundColor=[UIColor clearColor];

//设置对齐方式
aLabel.textAlignment = UITextAlignmentLeft;//文字靠左
aLabel.textAlignment = UITextAlignmentCenter;//文字居中
aLabel.textAlignment = UITextAlignmentRight;//文字靠右

//设置字体大小是否适应label宽度
aLabel.adjustsFontSizeToFitWidth=YES;//是YES时,这个属性就来控制文本基线的行为
在定义里面允许有以下格式显示:  
  typedef enum {    
 
      UIBaselineAdjustmentAlignBaselines,   //默认值文本最上端与label中间线对齐
 
      UIBaselineAdjustmentAlignCenters,   //text中间与label中间线对齐
 
     UIBaselineAdjustmentNone,    //text最低端与label中间线对齐
 
 } UIBaselineAdjustment;    



//设置是否是高亮
aLabel.highlighted=YES;
//高亮颜色
aLabel.highlightedTextColor=[UIColor redColor];


//设置阴影颜色
aLabel.shadowColor=[UIColor blueColor];
//阴影偏移量
aLabel.shadowOffset=CGSizeMake(0.5, 0.5);

//是否能和用户交互
aLabel.userInteractionEnabled=YES;
//文字是否可变,默认值是YES
aLabel.enabled=YES;


//设置文字过长时的显示格式
aLabel.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间
aLabel.lineBreakMode =UILineBreakModeTailTruncation,//截去尾部
aLabel.lineBreakMode =UILineBreakModeHeadTruncation;//截去头部
aLabel.lineBreakMode=UILineBreakModeCharacterWrap;//保留整个字符
aLabel.lineBreakMode=UILineBreakModeClip;//截去多余部分

在定义里面允许有以下格式显示:  
typedef enum {

 UILineBreakModeWordWrap = 0, //

 UILineBreakModeCharacterWrap,

  UILineBreakModeClip,//截去多余部分

  UILineBreakModeHeadTruncation,//截去头部

  UILineBreakModeTailTruncation,//截去尾部

  UILineBreakModeMiddleTruncation,//截去中间

} UILineBreakMode;