简体   繁体   English

UIButton文本颜色在ios7中选择时发生更改

[英]UIButton text color is changing on selection in ios7

I have a UIButton created in IB that I'm setting the title using NSAttributedString. 我在IB中创建了一个UIButton ,使用NSAttributedString.设置标题NSAttributedString.

NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:@"skip" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}];
[self.skipB setAttributedTitle:att forState:UIControlStateNormal];

Now normally (< ios7) when I set something only for state UIControlStateNormal it will default it for all the states so there is no selected or highlighted state which might change the color of the text when clicking on the button. 现在通常(<ios7),当我仅为状态UIControlStateNormal设置某些内容时,它将为所有状态默认设置,因此没有选定或突出显示的状态,当单击按钮时可能会更改文本的颜色。 However, when running in ios7 when you click on the button the text will change color like a light white mask is placed over it. 但是,在ios7中运行时,单击按钮时,文本将更改颜色,就像在其上放置了浅白色蒙版一样。 I would like it not to change color. 我希望它不改变颜色。 It's very possible that I've missed setting something that should be obvious, but has any one else seen this on ios7? 我很可能错过了一些显而易见的设置,但是还有其他人在ios7上看到过吗?

Hope this help 希望这个帮助

NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:@"skip" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}]; NSMutableAttributedString * att = [[NSMutableAttributedString alloc] initWithString:@“跳过”属性:@ {NSForegroundColorAttributeName:[UIColor redColor]}]; [self.skipB setAttributedTitle:att forState:UIControlStateNormal]; [self.skipB setAttributedTitle:att forState:UIControlStateNormal];

and

[self.skipB setAttributedTitle:att forState:UIControlStateSelected]; [self.skipB setAttributedTitle:att forState:UIControlStateSelected];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM