Change the font size and font style of UISearchBar iOS 7

后端 未结 9 832
借酒劲吻你
借酒劲吻你 2020-12-13 03:17

How can I change the font size and font style of UISearchBar in iOS 7?

UITextField *textField = [[searchBar subviews] objectAtIndex:1];
[textField setFont:[U         


        
9条回答
  •  轮回少年
    2020-12-13 03:38

    Try this, It's Working Fine for iOS 5.0 and up: (iOS 7 also)

    - (void)viewDidLoad
    {
    
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Helvetica" size:20]];
    
    }
    

    For iOS 8

    - (void)viewDidLoad
        {
    
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
                NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20],
          }];
    
        }
    

提交回复
热议问题