新手必看之UILabel

来源:互联网 发布:学会python要多久 编辑:程序博客网 时间:2024/05/01 08:43


初始化

UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
文字内容
//位置默认是靠左的
[label setText:@"文字"];

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

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

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

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

label.textAlignment = UITextAlignmentRight;//文字靠右

//    label添加边框

    label.layer.borderColor = [[UIColor whiteColor] CGColor];//颜色,使用cgcolor

    label.layer.borderWidth = 3;//宽度

    label.layer.cornerRadius = 10;//增加弧度

    label.layer.masksToBounds = YES;

    //设置子视图超越边界是否显示全 label.clipsToBounds



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

label.adjustsFontSizeToFitWidth=YES;//是YES时,这个属性就来控制文本基线的行为

//自动适应文本内容

[labelTwo sizeToFit];

//指定换行模式

labelTwo.numberOfLines = 4;

//设置label的旋转角度

labelThr.transform = CGAffineTransformMakeRotation(0.2);




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

  typedef enum {    
 
      UIBaselineAdjustmentAlignBaselines,   //默认值文本最上端与label中间线对齐 
 
      UIBaselineAdjustmentAlignCenters,   //text中间与label中间线对齐
 
     UIBaselineAdjustmentNone   //text最低端与label中间线对齐
 
 } UIBaselineAdjustment   



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


//设置阴影颜色
label.shadowColor=[UIColor blueColor];

//阴影偏移量
label.shadowOffset=CGSizeMake(0.5, 0.5);


在定义里面允许有以下格式显示:   
typedef enum {   
  UILineBreakModeWordWrap = 0, 
  UILineBreakModeCharacterWrap,    
  UILineBreakModeClip,//截去多余部分    
  UILineBreakModeHeadTruncation,//截去头部    
  UILineBreakModeTailTruncation,//截去尾部    
  UILineBreakModeMiddleTruncation,//截去中间   
UILineBreakMode;


0 0
原创粉丝点击