Bellots
Bellots

Reputation: 1773

RightBarButtonItems won't be shown anymore on iOS 11

The function self.navigationItem.rightBarButtonItem = cartBarButton won't show my item on the right of UINavigationController's NavBar

EDIT

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
        }

Upvotes: 0

Views: 179

Answers (1)

Ruslan Kolosovskyi
Ruslan Kolosovskyi

Reputation: 76

I had the similar issue with custom image view. My suggestion is to wrap your custom view into container view.

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)
}

Upvotes: 1

Related Questions