itch
itch

Reputation: 71

How to increase a scope title and search bar's font size in Xcode?

I've a search bar label with 3 scope titles in my app. on iPhone the font size for these titles is nice but on iPad is too small and I don't find a R.R feature to change like an normal text in the storyboard!! is there any easy way to solve this issue?

see the image here

Upvotes: 1

Views: 768

Answers (1)

Rocky
Rocky

Reputation: 3245

setScopeBarButtonTitleTextAttributes:forState: sets the text attributes for the search bar’ button’s title string for a given state.

 let font = UIFont.systemFont(ofSize: 24)   
 self.searchBar.setScopeBarButtonTitleTextAttributes([NSAttributedString.Key.font : font], for: .normal)

Answer for your question in comments.

Update font size of UITextField in searchBar

Extract the UITextField object from searchBar by iterating over subViews, and then update font of it.

extension UISearchBar {
    func update(font : UIFont?) {
        for view in (self.subviews[0]).subviews {
            if let textField = view as? UITextField {
                textField.font = font
            }
        }
    }
}

update font use this method when initialize searchBar object

@IBOutlet weak var searchBar:UISearchBar!{
        didSet {
            searchBar.update(font: UIFont.systemFont(ofSize: 30))
        }
    }

Upvotes: 3

Related Questions