【发布时间】:2018-06-25 09:28:56
【问题描述】:
我已经在这个错误上停留了好几天。我对 rightBarButtonItem 有疑问。我想创建一个自定义视图。在自定义视图中,有 2 项:标签、图像视图。当我输入这个时:
let customView = UIView()
customView.translatesAutoresizingMaskIntoConstraints = false
customView.backgroundColor = .black
customView.frame = CGRect(x: 0, y: 0, width: 90, height: 40)
let coinLabelNavigationBar = UILabel()
coinLabelNavigationBar.frame = CGRect(x: 40, y: 0, width: 30, height: 25)
coinLabelNavigationBar.translatesAutoresizingMaskIntoConstraints = false
coinLabelNavigationBar.text = "200"
coinLabelNavigationBar.font = UIFont(name: ".SFUIText-Medium", size: 20)
coinLabelNavigationBar.textColor = UIColor.white
let coinImage = UIImageView()
coinImage.frame = CGRect(x: 75, y: 0, width: 25, height: 25)
coinImage.translatesAutoresizingMaskIntoConstraints = false
coinImage.image = UIImage(named: "Coin")
customView.addSubview(coinLabelNavigationBar)
customView.addSubview(coinImage)
let rightBarButton = UIBarButtonItem(customView: customView)
navigationItem.rightBarButtonItem = rightBarButton
你有什么想法,如何解决它?
感谢您的回答。
【问题讨论】:
-
你能给我看一张描述你想如何显示你的栏按钮的图片吗?
标签: ios swift uinavigationbar uinavigationitem