UIButton 每行具有不同颜色的文本 [英] UIButton with different color text in each line

查看:32
本文介绍了UIButton 每行具有不同颜色的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个带有两行文本的 UIButton,每行的颜色不同.有这种可能吗?

I want to have a UIButton with two lines of text, with each line in different color. Is it possible to have like that ?

推荐答案

In Swift

var main_string = "Hello World"
var string_to_color = "World"
var range = (main_string as NSString).rangeOfString(string_to_color)
var attributedString = NSMutableAttributedString(string:main_string)
        attributedString.addAttribute(NSForegroundColorAttributeName, value: appSingleton.appRedColor , range: range)
self.celciusButton.setAttributedTitle(attributedString, forState: UIControlState.Normal)

这篇关于UIButton 每行具有不同颜色的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆