Change the font size of UISearchBar

前端 未结 19 1381
情歌与酒
情歌与酒 2020-12-04 15:08

How can I change the font size of UISearchBar ?

19条回答
  •  被撕碎了的回忆
    2020-12-04 15:50

    The safe way for performing this operation is as follows:

    for(UIView *subView in searchBar.subviews) {
        if ([subView isKindOfClass:[UITextField class]]) {
            UITextField *searchField = (UITextField *)subView;
            searchField.font = [UIFont fontWithName:@"Oswald" size:11];
        }
    }
    

    Why is this safer than the accepted answer? Because it doesn't rely on the index of the UITextField staying constant. (it's also a cleaner for loop)

提交回复
热议问题