resize UISearchBar

Discussion in 'iPhone/iPad Programming' started by kikko088, Dec 13, 2012.

  1. macrumors member

    Joined:
    Oct 13, 2010
    Location:
    Italy
    #1
    Hi at all I have a problem, I need to change uisearchbar frame, I try to di it in 2 way, the first time putting uisearchbar inside the tableview I can't change the frame with [uisearchbar appearance] or creating an IBOutlet property and changing the frame of this property.

    The second way I use is to create programmatically an uisearchbar and uisearchcontroller I can resize searchbar but if I don't initsearchcontroller with this searchbar I can't search anything, but If I init earchcontroller with this searchbar it take the default frame size.

    this is my code:

    Code:
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(56, 68, 200, 44)];
    self.searchBar.delegate = self;
    
    self.mySearchDisplayController = [[UISearchDisplayController alloc ]initWithSearchBar:self.searchBar contentsController:self];
    
    self.mySearchDisplayController.delegate = self;
    self.mySearchDisplayController.searchResultsDataSource = self;
    self.mySearchDisplayController.searchResultsDelegate = self;
    
    for (UIView *subview in self.searchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
    [subview removeFromSuperview];
    break;
    }
    if ([subview isKindOfClass:[UITextField class]]) {
    // Do your text field customisation in here
    [(UITextField *)subview setTextColor:[UIColor redColor]];
    }
    }
    
    [self.searchBar setBackgroundColor:[UIColor clearColor]];
    
    [self.mainView addSubview:self.searchBar];

    can you help me?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Have you tried changing the searchBar's frame after calling initWithSearchBar:contentsController:?
     
  3. thread starter macrumors member

    Joined:
    Oct 13, 2010
    Location:
    Italy
    #3
    yes I try but nothing, I get something good playing with the frame on the delegate method but however is not the right way because the frame is adjust after a moment.
    FOR NOW I find a solution on specific case adjusting the frame of table (not of single search bar)
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Well, you need to troubleshoot what is causing your frame to be readjusted without your "permission", as it were.
     

Share This Page