ios - 无法将作为自定义视图实现的 UILabel 的文本颜色设置为 UIBarButtonItem
问题描述
我想在工具栏中实现自定义标签,但无法更改其文本颜色:
// MARK: - Initialize the status label (toolbar)
func initStatusLabel() {
statusLabel.layer.borderColor = UIColor.red.cgColor;
statusLabel.layer.borderWidth = 1;
statusLabel.layer.masksToBounds = true;
statusLabel.layer.cornerRadius = 8;
statusLabel.font = statusLabel.font.withSize(12);
statusLabel.leftTextInset = 8;
statusLabel.rightTextInset = 8;
statusLabel.topTextInset = 8;
statusLabel.bottomTextInset = 8;
statusLabel.text = "Hello World";
statusLabel.adjustsFontSizeToFitWidth = true;
statusLabel.backgroundColor = .systemRed;
statusLabel.textColor = .white;
statusLabel.sizeToFit();
}
由于某些原因,白色将被忽略:
有任何想法吗?
解决方案
推荐阅读
- c# - 将外部 C# 脚本作为源添加到 PowerShell 脚本
- python - 如何在 Python 中将 Azure Blob 文件 CSV 转换为 Excel
- android - 我的应用程序可以完美展示广告,但 admob 应用程序页面上没有任何点击次数/展示次数/收入
- python - solidity - brownie compile - 状态 404 从 GitHub 获取包版本
- flutter - 是否可以根据布尔值添加或删除列表?
- python - Python数据类,default_factory包含列表的默认字典列表的正确方法?
- c++ - C++ 模块文件系统和 iostream 崩溃 g++
- neural-network - Tanh 激活函数的缩放
- javascript - 节点 package.json 脚本未在 Windows 上运行 - 找不到模块 yarn.js
- memory-management - Datadog % Mem 使用率和 RSS 内存