Swift - UIButton with two lines of text

前端 未结 10 1659
离开以前
离开以前 2020-11-30 23:38

I was wondering if it is possible to create a UIButton with two lines of text. I need each line to have a different font size. The first line will be 17 point and the seco

10条回答
  •  自闭症患者
    2020-12-01 00:25

    SWIFT 3 Syntax

    let str = NSMutableAttributedString(string: "First line\nSecond Line")
    str.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 17), range: NSMakeRange(0, 10))
    str.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 12), range: NSMakeRange(11, 11))
    button.setAttributedTitle(str, for: .normal)
    

提交回复
热议问题