Swfit:控件属性备注

设置文字

visitorButton.setTitle("注册", forState: UIControlState.Normal)

设置字体颜色

    visitorButton.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
    visitorButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Highlighted)

设置字体大小

visitorButton.titleLabel!.font = UIFont.systemFontOfSize(16);

另一种方式设置

  //行间距
    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

你可能感兴趣的:(Swfit:控件属性备注)