如何在 UIBarItem 中使用 setTitleTextAttributes:forState ?
如何在 iOS
的 UIBarItem
中使用 setTitleTextAttributes:forState:
?
如何设置NSDictionary
?无法使其工作,文档对此也不是很清楚。
来自文档:
setTitleTextAttributes:forState:
设置给定控件状态的标题文本属性:
- (void)setTitleTextAttributes:(NSDictionary *)attributes
forState:(UIControlState)state
参数:
属性:包含文本属性键值对的字典。您可以使用 NSString UIKit Additions Reference 中列出的键指定字体、文本颜色、文本阴影颜色和文本阴影偏移量。
state:要为其设置标题文本属性的控件状态。
How do you use setTitleTextAttributes:forState:
in UIBarItem
in iOS
?
How do you set the NSDictionary
? Can't make it work and documentation isn't very clear about that.
From the documentation:
setTitleTextAttributes:forState:
Sets the title’s text attributes for a given control state:
- (void)setTitleTextAttributes:(NSDictionary *)attributes
forState:(UIControlState)state
Parameters:
attributes: A dictionary containing key-value pairs for text attributes. You can specify the font, text color, text shadow color, and text shadow offset using the keys listed in NSString UIKit Additions Reference.
state: The control state for which you want to set the text attributes for the title.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
示例代码:
Example code:
Swift 5.0:
Swift 4.0:
目标 C 代码:
Swift 5.0:
Swift 4.0:
Objective C code:
这是 phix23 的代码,只是使用了更新的、我认为更清晰的语法:
Here's phix23's code, just with an updated, and I think cleaner, syntax:
Swift5设置
UIBarItem
标题颜色Swift5 set
UIBarItem
title color