在iOS 11上不再显示RightBarButtonItems

时间:2017-09-22 09:05:30

标签: ios swift xcode

函数self.navigationItem.rightBarButtonItem = cartBarButton不会在UINavigationController的NavBar

右侧显示我的项目

修改

let cartOriginalImage = UIImage.cart
        let cartButton = UIImageButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
        cartButton.setBackgroundImage(cartOriginalImage, for: .normal)
        cartButton.tintColor = Colors.Navigation.Tint.default
        cartButton.addTarget(self, action: #selector(MainViewController.cartButtonPressedInHomePage(sender:)), for: .touchUpInside)

        let cartBarButton = UIBarButtonItem(customView: cartButton)

        if let badge = badge {
            cartBarButton.badgeValue = badge
            cartBarButton.badge.backgroundColor = Colors.Navigation.Background.badge
            cartBarButton.badge.textColor = Colors.Navigation.Text.badge
        }

1 个答案:

答案 0 :(得分:1)

我在自定义图像视图中遇到了类似的问题。我的建议是将自定义视图包装到容器视图中。

private func configureUserAvatarView() {
    let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(avatarViewAction(_:)))
    let customView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
    customView.addGestureRecognizer(tapRecognizer)

    let imageView = FUIImageView(image: #imageLiteral(resourceName: "avatar_default_30х30"))
    imageView.isCircular = true
    imageView.contentMode = .scaleAspectFit
    imageView.frame = customView.bounds

    customView.addSubview(imageView)

    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: customView)
}