tags:

views:

1129

answers:

3

hi how can set image or clear background of search bar ? like note application ?

+1  A: 

I had problems w/ the answer above. I used the following.

for (UIView *subview in searchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
}
mj_
+2  A: 

mj_ has the answer that i used. i was just going to comment as such but i can't yet. So i'll just post my own answer with my implementation where I add a search bar to the top of a table view with a semi-transparent BG.

DLog(@"    Add search bar to table view"); 

//could be a UIImageView to display an image..?
vc = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)] autorelease];
vc.backgroundColor = [UIColor clearColor];
bg = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 45)] autorelease];
bg.backgroundColor = [UIColor blackColor];
bg.alpha = 0.567;
UISearchBar *sb = [[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 290, 45)] autorelease];
sb.barStyle                 = UIBarStyleBlackTranslucent;
sb.showsCancelButton        = NO;
sb.autocorrectionType       = UITextAutocorrectionTypeNo;
sb.autocapitalizationType   = UITextAutocapitalizationTypeNone;
sb.delegate                 = self;
[vc addSubview:bg];
[vc addSubview:sb];
table.tableHeaderView  = vc;

for (UIView *subview in sb.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
}   
Katbyte