Make UISearchBar background clear

后端 未结 17 1204
野的像风
野的像风 2021-01-07 17:17

I am not able to clear search bar I have tried to make it clear by setting its background color clear and I have also placed one image under searchbar

I have also ma

17条回答
  •  长发绾君心
    2021-01-07 17:52

    Subclass the uisearchbar and override initWithFrame and initWithCoder method and set the background color as

    // For searchbar created programmatically
    - (id)initWithCoder:(NSCoder *)aDecoder
    {
        self = [super initWithCoder:aDecoder];
        if (self) {
            [self configureSetup];
        }
        return self;
    }
    
    // For search bar created on xib
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self configureSetup];
        }
        return self;
    }
    
    - (void)configureSetup
    {
        self.backgroundColor = [UIColor clearColor];
    }
    

    and use the subclassed searchbar instead in place where you specified UISearchBar

提交回复
热议问题