How can I use the info light on a UIBarButtonItem
?
I don't want to use a custom image because the result is not very nice.
I would like to use the Apple "info" button on a UIBarButtonItem using Swift.
Select the UIBarButtonItem in Interface Builder , open the inspector (Command + Shift + I) , and select "Custom" under the dropdown next to Identifier .
You can set the font size for a specific BarButtonItem by overriding its ContentTemplate. Put an AccessText to this template and set its FontSize property. If you want to change the font size for all items in a specific BarManager, use the attached TextBlock. FontSize property.
A specialized button for placement on a toolbar, navigation bar, or shortcuts bar. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
There is no direct way to create such a bar button using the UIBarButtonItem
APIs.
You can although use a custom view configured with a .InfoLight
UIButton
, as suggested here:
// Create the info button
let infoButton = UIButton(type: .infoLight)
// You will need to configure the target action for the button itself, not the bar button itemr
infoButton.addTarget(self, action: #selector(getInfoAction), for: .touchUpInside)
// Create a bar button item using the info button as its custom view
let infoBarButtonItem = UIBarButtonItem(customView: infoButton)
// Use it as required
navigationItem.rightBarButtonItem = infoBarButtonItem
Feel free to leave a comment if you need any more help.
Adapting mokagio's excellent answer to Obj-C:
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(getInfoAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* infoBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
self.navigationItem.rightBarButtonItem = infoBarButtonItem;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With