更改具有多个标签的自定义 UIButton 的标签颜色
我正在创建一个带有多个标签的自定义按钮。我希望能够更改突出显示/普通 UIControlStates 上标签的文本颜色。我知道可以根据控件状态更改标题文本颜色,但我似乎无法弄清楚按钮内的自定义标签。有什么想法吗?
I am creating a custom button with multiple labels. I want to be able to change the text color of the labels on highlight/normal UIControlStates. I know its possible to change the title text color based on control states, but I can't seem to figure it out for custom labels within the button. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢@Rich 的想法。我对 UIButton 进行子类化并将此代码放入新类中。
这是我使用的代码:
Thanks for the idea @Rich. I subclassed UIButton and put this code in the new class.
Heres the code I used:
听起来你想使用一些继承的 UIControl 方法(例如 sendAction:to:forEvent:) 这提供了比 UIButton 更好的控制。
Sounds like you want to use some of the inherited UIControl methods (such as sendAction:to:forEvent:) This offers even finer control than with UIButton.
这有点复杂,但我有一本讨论这个问题的书,叫做《高级 iOS 4 开发》。基本上你必须使用运行时来交换 setHighlighted 方法。
编辑:从技术上讲,它适用于 tableviewcells,但它位于 这个在表格视图下变白
It's kinda complicated, but I have a book that talks about this it's called Advanced iOS 4 development. basically you have to use the runtime to swap out the setHighlighted method.
Edit: it's technically for tableviewcells but its in this under table view whiten