ios - 无法设置我的导航栏标题的字体大小
问题描述
我试图弄清楚如何使用 StackOverflow 做到这一点并做到了这一点:
[self.navController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont.systemFontSize:17 weight: UIFontWeightSemibold]}];
不幸的是,我收到一个错误,下划线UIFont.systemFontSize
显示Bad receiver type 'CGFloat'(aka 'double')
.
如何调整我的代码以使其发挥作用?
解决方案
您的语法已关闭
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight NS_AVAILABLE_IOS(8_2);
https://developer.apple.com/documentation/uikit/uifont/1619027-systemfontofsize?language=objc
您想在此处删除句点UIFont.systemFontSize
,而是使用UIFont systemFontOfSize:weight:
与其在设置属性时尝试将所有内容内联,不如将它们分开有时会有所帮助,即:
UIColor *whiteColor = [UIColor whiteColor];
UIFont *navBarTitleFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightSemibold];
[self.navigationController.navigationBar setTitleTextAttributes:@{
NSForegroundColorAttributeName: whiteColor,
NSFontAttributeName: navBarTitleFont
}];
推荐阅读
- node.js - TypeScript、express、node-dev *和*自定义文件类型加载器
- arrays - 谷歌表格搜索条目并给出结果
- javascript - 在这个正则表达式中必须纠正什么才能从印度尼西亚句子中提取发音?
- sql-server - 根据第 3 列的值计算两个不同的 SUM
- gradle - Intellij 无效的 Gradle JVM 配置
- sql - SQL Join:具有累积条件的双方所有值(Presto/AWS Athena)
- amazon-web-services - Dynamodb 触发器使用 lambda 更新另一个 dynamobo 表
- node.js - TypeError:无法在反应中读取正确的长度
- javascript - 如何在 JS 中使用 map 进行过滤
- d3.js - 在多个图表上组合 elasticY