您的位置:首页 > 产品设计 > UI/UE

UILable用法

2016-02-18 22:22 399 查看
原文:http://blog.sina.com.cn/s/blog_bf9843bf0101f7z7.html(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中间线对齐
 [/code] 
      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;//截去多余部分 
在定义里面允许有以下格式显示:
  
// NSParagraphStyletypedef NS_ENUM(NSInteger, NSLineBreakMode) {    NSLineBreakByWordWrapping = 0,    // Wrap at word boundaries, default    NSLineBreakByCharWrapping, // Wrap at character boundaries    NSLineBreakByClipping, // Simply clip    NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"    NSLineBreakByTruncatingTail, // Truncate at tail of line: "abcd..."    NSLineBreakByTruncatingMiddle // Truncate middle of line:  "ab...yz"} NS_ENUM_AVAILABLE(10_0,6_0);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: