导航栏中的自定义图标 Swift 3
Custom icons in navigation bar Swift 3
我在 Swift 3 中的自定义按钮有问题,我添加到资产文件夹中,在 ViewController 和 VC 中显示图标,但是当我在模拟器和我的 phone 中查看该项目仅显示表格,但不显示颜色和图标本身。
这是模拟器和我的图像 phone:
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style: .done, target: nil, action: nil)
navigationController?.navigationBar.backIndicatorImage = #imageLiteral(resourceName: "back")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")
最后是按钮图标:
在 Photoshop 中
在xcode中:
你检查过白色箭头实际上是透明区域而不是白色吗?
然后您可以为导航控制器设置 tintColor。尝试这样的事情:
navigationController?.navigationBar.tintColor = UIColor(..the color you want..)
确保按照 guidelines 创建导航栏项目。只是从您的图像中猜测,您似乎希望暗区被着色,而白色箭头显示为白色或透明?为了实现这一点,您需要使白色箭头透明。只要你的图标有像素信息,就会被着色。
我在 Swift 3 中的自定义按钮有问题,我添加到资产文件夹中,在 ViewController 和 VC 中显示图标,但是当我在模拟器和我的 phone 中查看该项目仅显示表格,但不显示颜色和图标本身。
这是模拟器和我的图像 phone:
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style: .done, target: nil, action: nil)
navigationController?.navigationBar.backIndicatorImage = #imageLiteral(resourceName: "back")
navigationController?.navigationBar.backIndicatorTransitionMaskImage = #imageLiteral(resourceName: "back")
最后是按钮图标:
在 Photoshop 中
在xcode中:
你检查过白色箭头实际上是透明区域而不是白色吗?
然后您可以为导航控制器设置 tintColor。尝试这样的事情:
navigationController?.navigationBar.tintColor = UIColor(..the color you want..)
确保按照 guidelines 创建导航栏项目。只是从您的图像中猜测,您似乎希望暗区被着色,而白色箭头显示为白色或透明?为了实现这一点,您需要使白色箭头透明。只要你的图标有像素信息,就会被着色。