remove the border of uitextfield in uisearchbar

回眸只為那壹抹淺笑 提交于 2019-12-04 17:43:40

Subclass UISearchBar and override layoutSubViews to remove the search bar background and the text field border subviews:

- (void)layoutSubviews
{    
    [super layoutSubviews];

    for (UIView *subview in self.subviews) {
        // Remove the default background
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            [subview removeFromSuperview];
        }

        // Remove the rounded corners
        if ([subview isKindOfClass:NSClassFromString(@"UITextField")]) {
            UITextField *textField = (UITextField *)subview;
            for (UIView *subsubview in textField.subviews) {
               if ([subsubview isKindOfClass:NSClassFromString(@"UITextFieldBorderView")]) {
                    [subsubview removeFromSuperview];
                }
            }
        }
    }
}
The Crazy Chimp

I'm not certain about this, however I suspect the only way you're going to be able to achieve a UISearchBar like that of the one in your image is to create a new subclass of UISearchBar. Using that you could set it up to look exactly like the one in your image.

This post may be of some help to you if you decide to go down the route of subclassing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!