[英]Cosmic mind - how to change title bar button's tint color
import UIKit
import Material
class MyVC: UITableViewController {
fileprivate var deleteButton: IconButton!
override func viewDidLoad() {
super.viewDidLoad()
prepareDeleteButton()
navigationItem.rightViews = [deleteButton]
}
// other delegates of UITableView
}
extension MyVC {
fileprivate func prepareDeleteButton() {
deleteButton = IconButton(image: UIImage(named: "Trash"))
deleteButton.tintColor = Color.red.base
deleteButton.addTarget(self, action: #selector(doSomething), for: .touchUpInside)
}
@objc
fileprivate func doSomething() {
print("delete accessory")
}
}
Note that MyVC
is pushed from another ViewController
. 请注意, MyVC
是从另一个ViewController
推送的。
In MyVC
, I want my trash can icon to be at the upper right corner of the screen, which is navigationItem.rightViews = [deleteButton]
, and to have red base color deleteButton.tintColor = Color.red.base
. 在MyVC
,我希望我的垃圾桶图标位于屏幕的右上角,即navigationItem.rightViews = [deleteButton]
,并具有红色的基色deleteButton.tintColor = Color.red.base
。
But it does not work in the code above, the trash can is still black. 但这在上面的代码中不起作用,垃圾箱仍然是黑色的。 How can I change its tint color? 如何更改其色调颜色?
It seems that my trash icon is a little bigger then other Cosmic Mind icons at the same rightViews
although it has the same size as Cosmic Mind icons (24x24 @1x). 在相同的rightViews
,我的回收站图标似乎比其他Cosmic Mind图标大一些,尽管它的大小与Cosmic Mind图标相同(24x24 @ 1x)。 Is it true? 是真的吗 How to make it a little smaller? 如何使其更小?
Regards, 问候,
The issue with your code is that you are not using the correct rendering mode. 代码的问题在于您没有使用正确的渲染模式。 Try this: 尝试这个:
deleteButton = IconButton(image: UIImage(named: "Trash")!.withRenderingMode(.alwaysOriginal))
All the best! 祝一切顺利!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.