Swift - UIButton with two lines of text

前端 未结 10 1665
离开以前
离开以前 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:31

    my way:

    func setButtonTitle(title: String, subtitle: String, button: UIButton){
            //applying the line break mode
            button.titleLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping;
            let title = NSMutableAttributedString(string: title, attributes: Attributes.biggestLabel)
            let subtitle = NSMutableAttributedString(string: subtitle, attributes: Attributes.label)
            let char = NSMutableAttributedString(string: "\n", attributes: Attributes.biggestLabel)
            title.append(char)
            title.append(subtitle)
            button.setAttributedTitle(title, for: .normal)
        }
    

提交回复
热议问题