Negative spacer for UIBarButtonItem in navigation bar on iOS 11

后端 未结 4 1075
不知归路
不知归路 2020-12-05 02:37

In iOS 10 and below, there was a way to add a negative spacer to the buttons array in the navigation bar, like so:

UIBarButtonItem *negativeSpacer = [[UIBarB         


        
4条回答
  •  一个人的身影
    2020-12-05 03:24

    Just a workaround for my case, it might be helpful to some people. I would like to achieve this:

    and previously I was using the negativeSpacer as well. Now I figured out this solution:

            let logoImage = UIImage(named: "your_image")
            let logoImageView = UIImageView(image: logoImage)
            logoImageView.frame = CGRect(x: -16, y: 0, width: 150, height: 44)
            logoImageView.contentMode = .scaleAspectFit
            let logoView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 44))
            **logoView.clipsToBounds = false**
            logoView.addSubview(logoImageView)
            let logoItem = UIBarButtonItem(customView: logoView)
            navigationItem.leftBarButtonItem = logoItem
    

提交回复
热议问题