8.5 C
Canberra
Wednesday, December 3, 2025

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


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

import UIKit

class ViewController: UIViewController {

  override func viewDidLoad() {
    tremendous.viewDidLoad()
    // Do any further 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 take advantage of constraint to power the dimensions to be 12×12.

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

enter image description here

Nonetheless, 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

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles