Cosmic mind - 如何更改标题栏按钮的色调

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")
    }
}

请注意 MyVC 是从另一个 ViewController 推送的。

MyVC 中,我希望我的垃圾桶图标位于屏幕的右上角,即 navigationItem.rightViews = [deleteButton],并且底色为红色 deleteButton.tintColor = Color.red.base

但是在上面的代码中不行,垃圾桶还是黑色的。我怎样才能改变它的色调?

我的垃圾桶图标似乎比其他 Cosmic Mind 图标大一点 rightViews 尽管它与 Cosmic Mind 图标大小相同 (24x24 @1x)。是真的吗?怎么让它变小一点?

此致,

您的代码存在问题,因为您没有使用正确的渲染模式。试试这个:

deleteButton = IconButton(image: UIImage(named: "Trash")!.withRenderingMode(.alwaysOriginal))

祝一切顺利!