UILabel 文本控件

UILabel  文本控件





     UILabel 是iOS开发中用来显示文字的控件,是UIView的子类.右移具有UIView的所有功能,只不过比UIView多了文字显示的功能.
     UILabel的使用过程和UIView类似:
     1.创建对象
     2.配置属性
     3.添加到父视图
     4.释放所有权



 

    UILabel * v1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    v1.backgroundColor =[UIColor whiteColor];
  

设置label上显示的文字
    v1.text = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 

label 文字位置
    0 NSTextAlignmentLeft        左对齐
     1 NSTextAlignmentCenter    居中
     2 NSTextAlignmentRight      右对齐
    v1.textAlignment = NSTextAlignmentCenter;
  

文字换行  默认为1 如果不限制行数将值设置为 0
    v1.numberOfLines = 0;
   

换行的标准(文本的截取原则) 默认 以单词为一组
   
     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"
    
    v1.lineBreakMode = NSLineBreakByClipping;
    
  

设置阴影的偏移量 正值向X Y 轴 正方向偏移 负值向反方向偏移.
    v1.shadowOffset = CGSizeMake(2, 2) ;
   

设置阴影的颜色
    v1.shadowColor = [UIColor yellowColor];
  

label 文字颜色
    v1.textColor = [UIColor redColor];
   

label 文字大小
     (1)字体样式
    
    (2)字号(默认 17)
     systemFontOfSize: 默认使用系统默认字体,可以更改字体大小.
    v1.font = [UIFont systemFontOfSize:25];
    
    v1.font = [UIFont fontWithName:@"Thonburi-Bold" size:20];
    UIFont familyNames 获取字体家族的名字
        NSLog(@"%@",[UIFont familyNames]);
  

UIFont fontNamesForFamilyName:@"Thonburi" 获取对应字体下属的字体名字
       NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Thonburi"]);
    
    
    [_View addSubview:v1];
    [v1 release];
    
    
    

}