iOS 11 UIBarButtonItem images not sizing
BarButtonItem (iOS11\xCode9) uses autolayout instead of frames. Try this (Swift):
if #available(iOS 9.0, *) {
cButton.widthAnchor.constraint(equalToConstant: customViewButton.width).isActive = true
cButton.heightAnchor.constraint(equalToConstant: customViewButton.height).isActive = true
}
Objective C
if (@available(iOS 9, *)) {
[cButton.widthAnchor constraintEqualToConstant: standardButtonSize.width].active = YES;
[cButton.heightAnchor constraintEqualToConstant: standardButtonSize.height].active = YES;
}
iOS 11 UIBarButtonItem ImageView size bug
In iOS 11 you must need us auto-layout instead of frames
Like below
myButton.widthAnchor.constraint(equalToConstant: customViewButton.width).isActive = true
myButton.heightAnchor.constraint(equalToConstant: customViewButton.height).isActive = true
How to set UIBarButton size in iOS 11 to match size in iOS 10
Your approach is correct: custom bar button items now do autolayout, so you must add constraints to set the size. This is a much-requested feature, so don't worry, be happy!
The constraints you must add are like the constraints for a table cell height: you must add sufficient constraints to size the bar button item's custom view completely from the inside out. For example, give it absolute width and height constraints, or give its contents width and height constraints plus constraints pinning them to the boundaries of the custom view itself.
Change size of UIBarButtonItem (image) in Swift 3
In the end I did it like this and it worked:
let moreButton = UIButton(frame: CGRect(x: 0, y: 0, width: 35, height: 35))
moreButton.setBackgroundImage(UIImage(named: "ic_more_vert_3"), for: .normal)
moreButton.addTarget(self, action: #selector(TableViewController.handleMore), for: .touchUpInside)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: moreButton)
Answer from: Change width of a UIBarButtonItem in a UINavigationBar in swift
iOS 11 navigation bar / uibarbutton items rendering issues
refer to UIBarButtonItem on iOS 11
UIBarButtonItem
uses autolayout instead of dealing with frames.
That's why the button is got stretched .
Modify:
widthConstraint = leftBackBtn.WidthAnchor.ConstraintEqualTo(27);
heightConstraint = leftBackBtn.HeightAnchor.ConstraintEqualTo(20);
widthConstraint.Active = true;
heightConstraint.Active = true;
How big should a UIBarButtonItem image be?
As of iOS 11, the Human Interface Guidelines suggest glyphs be about 25×25 points in toolbars and navigation bars, up to a maximum of about 28 points. (And the HIG should definitely be in your bookmarks if you're working on iOS apps!)
That would translate to images 25px square for older devices like iPad 2 / Mini, 50px square for most current devices like iPhone 8 or iPad, and 75px square for Retina HD devices (the iPhone 6/7/8 Plus, or iPhone X). Asset catalogs will help immensely in keeping the different asset sizes organized (and Xcode can even generate them from vector sources these days).
Related Topics
Ios13 Share Sheet: How to Set Preview Thumbnail When Sharing Uiimage
Round Top Corners of a Uiview and Add Border
In iOS, What's the Difference Between Autoresizing, Autolayout, and Constraints
How to Send Email Using Mfmailcomposeviewcontroller in Simulator
Main.Async VS Main.Sync() VS Global().Async in Swift3 Gcd
Asset Catalog: Access Images with Same Name in Different Folders
Find Uialertview Without Having Reference to It iOS 7
Launch Other Application Without Url Schema in Iphone
React Native Xcode Project Product Archive Fails with Duplicate Symbols for Architecture Arm64
Get Pixel Value from Cvpixelbufferref in Swift
Uicontroleventtouchdragexit Triggers When 100 Pixels Away from Uibutton
Alamofire with a Self-Signed Certificate/Servertrustpolicy
Exclude Pod When Porting to MAC with Catalyst
Instagram Hooks Pre-Select Media Issue
Combining 'And' and 'Or' Condition in Nspredicate
Disable Wkwebview for Opening Links to Redirect to Apps Installed on My Iphone