HomeiOS Developmentuikit - Alter UINavigationBar's UIBarButtonItem measurement and margin in iOS 26

uikit – Alter UINavigationBar’s UIBarButtonItem measurement and margin in iOS 26


I need to alter the dimensions of my navigation bar button merchandise. Here is a minimal repro code:

import UIKit

class ViewController: UIViewController {

  override func viewDidLoad() {
    tremendous.viewDidLoad()
    // Do any extra setup after loading the view.
    
    let w: CGFloat = 64
    let h: CGFloat = 64

    let v1 = UIView(body: CGRectMake(0, 0, w, h))
    let v2 = UIView(body: CGRectMake(0, 0, w, h))
    let v3 = UIView(body: CGRectMake(0, 0, w, h))
    let v4 = UIView(body: CGRectMake(0, 0, w, h))
    let v5 = UIView(body: CGRectMake(0, 0, w, h))
    let v6 = UIView(body: CGRectMake(0, 0, w, h))

    v1.backgroundColor = .pink
    v2.backgroundColor = .inexperienced
    v3.backgroundColor = .yellow
    v4.backgroundColor = .grey
    v5.backgroundColor = .cyan
    v6.backgroundColor = .purple
    
    let views: [UIView] = [v1, v2, v3, v4, v5, v6]
    
    navigationItem.rightBarButtonItems = views.map { v in
      v.anchor(to: CGSizeMake(12, 12))
      let merchandise = UIBarButtonItem(customView: v)
      if #accessible(iOS 26.0, *) {
        merchandise.hidesSharedBackground = true
      }
      return merchandise
    }
  }
}

extension UIView {
  func anchor(to measurement: CGSize) {
    translatesAutoresizingMaskIntoConstraints = false
    let constraints = [
      heightAnchor.constraint(equalToConstant: size.height),
      widthAnchor.constraint(equalToConstant: size.width)
    ]
    NSLayoutConstraint.activate(constraints)
  }
}

In my code, every view’s measurement is initialized as 64×64, later I exploit constraint to drive the dimensions to be 12×12.

On iOS 18, the dimensions is accurately up to date:

enter image description here

Nevertheless, on iOS 26, it seems to be like solely the peak is revered, however not the width.

enter image description here

Additionally, discover the horizontal hole between every merchandise on iOS 26 is bigger than iOS 18.

How can I protect each of my sizes and gaps on iOS 26 in order that it seems to be the identical as iOS 18?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments