Reputation: 83
I moved the search bar from UIView
to navigationItem
in UIViewController
when I was updating the application from 10 to 11 iOS SDK.
Further, I set to position a background image in UISearchBar
with a vertical offset because the distance between the logo and searchBar was small.
searchBar.setSearchFieldBackgroundImage(searchFieldImage, for: .normal)
searchBar.searchFieldBackgroundPositionAdjustment = UIOffset(horizontal: 0, vertical: 4)
But I can't right be positioning the Cancel button on vertical. How can I set the vertical position the Cancel button in UISearchBar
, or title in button?
Upvotes: 2
Views: 1336
Reputation: 1241
let cancelButton = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self])
let offset = UIOffset(horizontal: 0, vertical: 7)
cancelButton.setTitlePositionAdjustment(offset, for: .default)
Also take a look at apple doc here.
Upvotes: 4
Reputation: 8512
Access the cancel button as follows:-
UIBarButtonItem *cancelButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
Now try to update the frame(y axis) of cancelButton
.
Upvotes: 4
Reputation: 6067
You can increase searchBar Height heightAnchor.constraint
to increase navigation Bar Height to fix image logo issue , check it
In IOS 11
searchController.searchBar.heightAnchor.constraint(equalToConstant: 50).isActive = true
Upvotes: 0