import UIKit
class ViewController: UIViewController ,UITextFieldDelegate,UITextViewDelegate,UIActionSheet Delegate,UIAlertViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
//UILabel的创建
let label:UILabel = UILabel()
//设置frame大小
label.frame = CGRectMake(10, 40, 200, 30)
label.backgroundColor = UIColor.grayColor()
label.text = "www.baidu.com"
label.textColor = UIColor.redColor()
//设置文字对齐方式
label.textAlignment = NSTextAlignment.Center
//设置阴影颜色
label.shadowColor = UIColor.blackColor()
//设置阴影大小
label.shadowOffset = CGSizeMake(-5, 5)
label.font = UIFont(name: "Zapfino", size: 20)
//文字过长时省略形式
label.lineBreakMode = NSLineBreakMode.ByTruncatingMiddle
//文字大小自适应标签宽度
label.adjustsFontSizeToFitWidth = true
//显示文字行数设置(默认显示是1行)
label.numberOfLines = 0
//设置文本高亮
label.highlighted = true
//设置文本高亮颜色
label.highlightedTextColor = UIColor.greenColor()
//富文本设置
// var attributeString =NSMutableAttributedString(string: "www.cometoqingdao")
// attributeString.addAttribute(NSFontAttributeName, value: UIFont(name: "HelveticaNeue-Bold", size: 16)!, range: NSMakeRange(0,6))
// attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor(), range: NSMakeRange(0, 3))
// attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.blueColor(), range: NSMakeRange(3, 3))
// label.attributedText = attributeString
self.view.addSubview(label)
}
}
网友评论