1 // Mark: 2. 创建label
2 private func creatLabel(title: NSString)->UILabel{
3 /// 创建label
4 let titleL = UILabel(frame: CGRectMake(100, 64, 200, 60))
5
6 titleL.text = title as String
7 titleL.textColor = UIColor.redColor()
8 titleL.backgroundColor = UIColor.yellowColor()
9 titleL.layer.cornerRadius = 10.0
10 titleL.layer.masksToBounds = true
11 titleL.textAlignment = NSTextAlignment.Center
12 titleL.font = UIFont.systemFontOfSize(16.0)
13 // 阴影
14 titleL.shadowColor = UIColor.cyanColor()
15 titleL.shadowOffset = CGSizeMake(-2, 2)
16 // 省略方式
17 titleL.lineBreakMode = NSLineBreakMode.ByTruncatingTail
18 // titleL.adjustsFontSizeToFitWidth = true
19 titleL.numberOfLines = 2
20
21 // 富文本
22 let attr = NSMutableAttributedString(string: "NSMutableAttributedStringNSMutableAttributedStringNSMutableAttributedString")
23
24 attr.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(25.0), range: NSMakeRange(0, 6))
25 attr.addAttribute(NSForegroundColorAttributeName, value: UIColor.purpleColor(), range: NSMakeRange(7, 15))
26 titleL.attributedText = attr
27
28 self.view.addSubview(titleL)
29 return titleL;
30 }