0
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)。这是真的吗?如何让它变小一点?

问候,

4

1 回答 1

1

您的代码的问题是您没有使用正确的渲染模式。尝试这个:

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

一切顺利!

于 2017-05-11T15:21:42.253 回答