Removing the image on the left of an UISearchbar

前端 未结 17 1865
攒了一身酷
攒了一身酷 2020-12-29 20:44

Can I remove the image on the left of an UISearchbar and add a new image?

17条回答
  •  旧巷少年郎
    2020-12-29 21:02

    you can subclass UISearchBar and then use this method:

    - (void)setTextFieldLeftView:(UIView *)view
    {
        UITextField *searchField = nil;
        for (UIView *subview in self.subviews)
        {
            if ([subview isKindOfClass:[UITextField class]])
            {
                searchField = (UITextField *)subview;
                break;
            }
        }
    
        if (searchField != nil) 
        {
            searchField.leftView = view;
        }
    }
    

提交回复
热议问题