前端之家收集整理的这篇文章主要介绍了
swift02-创建Label,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//创建Label
var label = UILabel(frame:CGRectMake(20,100,30))
label.text = "labelfwade"
//背景颜色和文字颜色的设置
label.textColor = UIColor.blueColor()
label.backgroundColor = UIColor.redColor()
//对齐方式的设置
label.textAlignment = NSTextAlignment.Right
label.shadowColor = UIColor.brownColor()
label.shadowOffset = CGSizeMake(-5,-5)
label.font = UIFont(name:"",size: 20)
//文字过长时的省略方式
label.lineBreakMode = NSLineBreakMode.ByTruncatingMiddle
label.adjustsFontSizeToFitWidth = true;
label.numberOfLines = 0;
label.highlighted = true
label.highlightedTextColor = UIColor.purpleColor()
var attributeString = NSMutableAttributedString(string:"hello,world")
attributeString.addAttribute(NSFontAttributeName,value: UIFont(name: "HelveticaNeue-Bold",size: 10)!,range: NSMakeRange(0,5))
attributeString.addAttribute(NSForegroundColorAttributeName,value: UIColor.blueColor(),5))
attributeString.addAttribute(NSBackgroundColorAttributeName,value: UIColor.greenColor(),range: NSMakeRange(3,3))
label.attributedText = attributeString
self.view.addSubview(label)
原文链接:https://www.f2er.com/swift/323273.html