iOS - Customizing Cancel button of UISearchBar

后端 未结 4 2296
我在风中等你
我在风中等你 2020-12-14 22:16

In my iOS5 iPhone application, i\'m setting the tint color of search bar using following code:

searchBar.tintColor = UIColorMake(@\"#EFEFEF\");
4条回答
  •  醉话见心
    2020-12-14 22:59

    You can customize the Cancel button on iOS 5 by using the appearance proxy. You need to change appearance of UIBarButtonItem when contained in UISearchBar. For example to change the title font of the Cancel button you can use:

    NSDictionary *attributes =
        [NSDictionary dictionaryWithObjectsAndKeys:
         [UIColor whiteColor], UITextAttributeTextColor,
         [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5], UITextAttributeTextShadowColor,
         [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
         [UIFont systemFontOfSize:12], UITextAttributeFont,
         nil];
    [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
        setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
        setTitleTextAttributes:attributes forState:UIControlStateHighlighted];
    

提交回复
热议问题