iOS:我可以更改Button Tittle的颜色部分吗?

时间:2015-12-29 02:47:16

标签: ios uibutton

我是iOS新手。我想知道如何更改UIButton标题的每个部分的颜色。

例如,我的UIButton中的标题的一部分是黑色,另一部分UIButton中的标题部分是黄色

这是描述图像 Here is the button that I want

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

您可以使用NSMutableAttributedString,然后将其添加到[button setAttributedTitle:attString forState:UIControlStateNormal];

按钮

要更改属性字符串中范围的颜色,请阅读this,基本上只是属性字典中的一个

阅读此SO Question

答案 1 :(得分:0)

我使用下面的代码解决了我的问题 对于WebElement element= driver.findElement(By.xpath("YOUR Locator")); JavascriptExecutor executor = (JavascriptExecutor) driver; executor.executeScript("arguments[0].click();", element);

UILabel

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: self.lblFriendBand.attributedText]; [text addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(1, 2)]; [self.lblFriendBand setAttributedText: text];

UIButton
相关问题