設(shè)置文字
visitorButton.setTitle("注冊(cè)", forState: UIControlState.Normal)
設(shè)置字體顏色
visitorButton.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
visitorButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Highlighted)
設(shè)置字體大小
visitorButton.titleLabel!.font = UIFont.systemFontOfSize(16);
另一種方式設(shè)置
//行間距
let content = "content"
let attributedString = NSMutableAttributedString.init(string: content)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, content.characters.count))
label.attributedText = attributedString
//字體顏色
let attributedString = NSMutableAttributedString(string: self.integralLabel.text!)
let color = UIColor.redColor()
let normalAttributes = [NSForegroundColorAttributeName : color]
attributedString.addAttributes(normalAttributes, range: NSMakeRange(0,2))
self.integralLabel.attributedText = attributedString
//字體大小 和顏色
let attributedString = NSMutableAttributedString(string: self.newRanking.text!)
let color = UIColor.redColor()
let normalAttributes = [NSForegroundColorAttributeName : color,NSFontAttributeName:UIFont.boldSystemFontOfSize(20)]
attributedString.addAttributes(normalAttributes, range: NSMakeRange(5,2))
self.newRanking.attributedText = attributedString