I want the view of the background of the UISearchBar to be transparent.

Asked 2 months ago, Updated 2 months ago, 1 views

I would like to make the black view on the image diagram transparent.

The image is search.barTintColor=[UIColor clearColor];

That's what it was.If anyone understands, please take care of me.

Enter a description of the image here

ios

2022-09-30 13:45

1 Answers

I think it can be solved by setting the search style of the UISearchBar to minimal.

Additional
I can't write enough comments, so I'll add them here.

UISearchBar

·UISearchBarBackGround (subclass of UIImageView)
·UISearchBarTextField (subclass of UITextField)

I think it would be possible to do this by configuring two views.

If you follow the UISearchBar SubView, you will find the appropriate View.
Try fiddling with the necessary parts.

The following sources

// Get subview of UISearchBar
for (UIView* subview in self.SearchBar.subviews) {

    // Obtain a subview of a UISearchBar
    for (UIView* secondSubView in subview.subviews) {

        // Get background view
        if([secondSubView isKindOfClass:[UIImageView class]]) {

                // pass nil in setImage
                (UIImageView*) secondSubView setImage:nil ;

                // Specify any color
                [secondSubView setBackgroundColor: [UIColor clearColor];
        }

        // Get text field portion
        if([secondSubView isKindOfClass:[UITextField class]]) {
            [(UITextField*) secondSubView setBackgroundColor: [UIColor whiteColor];   
        }
    }   
}

Sample


2022-09-30 13:45

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.