【发布时间】:2019-10-03 07:58:52
【问题描述】:
我在 swift 4 中实现了一个自定义的后退按钮,但该按钮不显示。我可以在它所在的层中看到它,但它在后面,不能把它带到前面。 这是我在 viewDidload 中的代码:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
collectionView?.translatesAutoresizingMaskIntoConstraints = false
collectionView?.contentInset = UIEdgeInsets(top: 8, left: 0, bottom: 58, right: 0)
collectionView?.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0)
collectionView?.alwaysBounceVertical = true
collectionView?.backgroundColor = UIColor(patternImage: UIImage(named: "chat-bg")!)
collectionView?.register(ChatMessageCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.keyboardDismissMode = .interactive
let username = Auth.auth().currentUser?.displayName
let backbutton = UIButton(type: .custom)
backbutton.translatesAutoresizingMaskIntoConstraints = false
backbutton.setImage(UIImage(named: "back"), for: .normal) // Image can be downloaded from here below link
backbutton.setTitle(username, for: .normal)
backbutton.setTitleColor(backbutton.tintColor, for: .normal) // You can change the TitleColor
backbutton.addTarget(self, action: #selector(backAction), for: .touchUpInside)
self.navigationController?.navigationItem.backBarButtonItem = UIBarButtonItem(customView: backbutton)
self.navigationController?.navigationBar.addSubview(backbutton)
setupInputComponents()
setupKeyboardObservers()
}
【问题讨论】:
-
显示分配给collectionView的约束。
标签: ios swift xcode user-interface uinavigationbar