swift中UILabel的使用

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. let text = "swift中使用label。label在swift中的使用方法。swift中使用label。label在swift中的使用方法。swift中使用label。label在swift中的使用方法。"  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 实例化  
  2. let label:UILabel = UILabel(frame: CGRectMake(10.010.0, (CGRectGetWidth(self.view.frame) - 10.0 * 2), 60.0))  
  3. // 加到父视图  
  4. self.view.addSubview(label)  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 内容  
  2. label.text = text  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 字体属性设置  
  2. label.textColor = UIColor.blackColor()  
  3. label.textAlignment = NSTextAlignment.Left  
  4. label.font = UIFont(name: "Copperplate", size15.0)  
  5. label.lineBreakMode = NSLineBreakMode.ByTruncatingTail  
  6. label.adjustsFontSizeToFitWidth = true  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 行数显示,默认为1行  
  2. // 多行显示  
  3. label.numberOfLines = 0  
  4. // 只显示2行  
  5. // label.numberOfLines = 2  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 文本高亮  
  2. label.highlighted = true  
  3. label.highlightedTextColor = UIColor.blueColor()  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 阴影设置  
  2. label.shadowColor = UIColor.brownColor()  
  3. label.shadowOffset = CGSizeMake(2.02.0)  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // layer层设置  
  2. label.layer.cornerRadius = 5.0  
  3. label.layer.masksToBounds = true  
  4. label.layer.borderColor = UIColor.redColor().CGColor  
  5. label.layer.borderWidth = 1.0  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 其他属性  
  2. label.backgroundColor = UIColor.greenColor()  
  3. label.hidden = false  

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 富文本属性  
  2. let label02:UILabel = UILabel(frame: CGRectMake(10.0, (CGRectGetHeight(label.frame) + CGRectGetMaxY(label.frame) + 10.0), (CGRectGetWidth(self.view.frame) - 10.0 * 2), 40.0))  
  3. self.view.addSubview(label02)  
  4. label02.backgroundColor = UIColor.yellowColor()  
  5. label02.font = UIFont(name: "Thonburi", size12.0)  
  6.   
  7. let text00 = "label的用法"  
  8. // 定义富文本  
  9. let attributeString = NSMutableAttributedString(string: text00)  
  10. // 从文本0开始6个字符字体HelveticaNeue-Bold,16号  
  11. attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold", size20.0)!,  
  12.             range: NSMakeRange(05))  
  13. // 设置字体颜色  
  14. attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSMakeRange(05))  
  15. // 设置文字背景颜色  
  16. attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.greenColor(), range: NSMakeRange(05))  
  17. // 富文本内容显示  
  18. label02.attributedText = attributeString  


注意:多行显示时,参数numberOfLinesfontframe中的height,三者是有关联的。如果height小于fone,或小于numberOfLines的行数时,则会显示不全。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值