UILabel 文本控件

发布时间:2020-06-20 14:17:21 作者:缘起愿落
来源:网络 阅读:397





     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];
    
    
    

}




推荐阅读:
  1. Swift基础教程(swift代码创建第一个控件之UILabel
  2. iOS-UI-基本控件之UILabel

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

uilabel 文本控件

上一篇:全文检索ElasticSearch与Spring boot集成实例

下一篇:nginx的平滑升级

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》