简体   繁体   English

宇宙思维-如何更改标题栏按钮的颜色

[英]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.

相关问题 如何在 iOS 10 中更改特定栏按钮项的色调颜色 - How to change a specific bar button item tint color in iOS 10 当搜索栏处于活动状态和禁用状态时,如何更改搜索栏的颜色和表视图的颜色? - How to change the bar tint color of search bar and table view's color when search bar is active and disabled? 如何更改 UITextField 上清除按钮的色调颜色 - How to change the tint color of the clear button on a UITextField iOS启动情节提要:如何更改选项卡栏的色调颜色? - iOS Launch Storyboard: How can I change a Tab Bar's tint color? iOS 8 中的导航栏栏、色调和标题文本颜色 - NavigationBar bar, tint, and title text color in iOS 8 在Appdelegate中设置后如何更改导航栏的颜色? - How to change navigation bar tint color after setting in Appdelegate? 我怎么能动画UINavigationBar的条形色调变化,而不是UITabBar? - How is it I can animate the change in bar tint color of a UINavigationBar but not a UITabBar? iPad:如何更改弹出框中导航栏项目的颜色? - iPad: How to change the tint color of a navigation bar item in a popover? 如何更改 SwiftUI 中推送视图的导航栏色调颜色? - How to change navigation bar tint color for pushed view in SwiftUI? ios物料设计宇宙思维选项卡栏实现 - ios material design cosmic mind tab bar implementation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM