2

I realize there will be comments such as this is duplicate :

Change the Width of UISearchBars on a TableView

I think it is not. Why am I unable to change the width in the storyboard?

enter image description here

I can write in the width field any value but as soon as I push return/enter key value 320 is restored.

I've tried also to do it in view did load method :

searchBar.frame = CGRectMake(0, 0, 222, 45);

With zero success again, does anyone knows how to do this? I have an indexed table and the letters on the right overlap with the search text field and it looks really ugly.

Update

In simple words here is what I want (Conceptually) :

enter image description here

This is what I managed to produce :

enter image description here

Again let me re-iterate the issue "I'm trying to resize my search bar so the letters won't overlap it".

I've tried taus-iDeveloper suggestion, it did resize but the table cells/sections overlapped it.

Also tried this :

Changing the size of the UISearchBar TextField?

I manage to resize it in storyboard but when application is running the size hasn't change.

enter image description here

I'm all out of ideas what to try next ..

Update 2

I accepted the answer because it has some elements of solution, I came to conclusion that this cannot be done using storyboard only programmatically, solution :

//Add the search bar uiview wrapper
    UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.frame.size.width, 44.0)];

    //Add the search bar and navigation item to fill in the remaining space
    UINavigationBar *remainingSearchSpace = [[UINavigationBar alloc] initWithFrame:CGRectMake(290, 0.0, (self.tableView.frame.size.width-290), 44.0)];

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 290, 44.0)];
    searchBar.delegate = self;
    [searchBarView addSubview:searchBar];
    [searchBarView addSubview:remainingSearchSpace];
    self.tableView.tableHeaderView = searchBarView;
rene
  • 41,474
  • 78
  • 114
  • 152
London
  • 14,986
  • 35
  • 106
  • 147
  • Can you make sure to put more relevant tags on your questions? ('ios5' isn't really relevant here, but 'uisearchbar' certainly is. While I could retag this myself, you might not notice it.) –  Jun 06 '12 at 13:15

3 Answers3

1

try this out: in .h file,

@interface SearchBarController : UIViewController <UISearchBarDelegate>

@property (nonatomic, retain) UISearchBar *mySearchBar;

In .m file,

@synthesize mySearchBar;
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = NSLocalizedString(@"SearchBarTitle", @"");

    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];    // use the table view background color

    self.mySearchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 44.0)] autorelease];
    self.mySearchBar.delegate = self;
    self.mySearchBar.showsCancelButton = YES;
    self.mySearchBar.showsBookmarkButton = YES;
    [self.view addSubview: self.mySearchBar];

    // provide tint coloring and background image only if its available
    if (![self.mySearchBar respondsToSelector:@selector(setSearchFieldBackgroundImage:forState:)])
    {
        // hide the segmented control allowing for various content options
        self.contentOptions.hidden = YES;
    }
}

Hope this helps!!

jpsimard-nyx
  • 8,587
  • 6
  • 32
  • 48
taus-iDeveloper
  • 681
  • 2
  • 8
  • 22
1

Use these UISearchDisplayDeletegate functions:

- (void) searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
istruble
  • 13,363
  • 2
  • 47
  • 52
Yosra Nagati
  • 780
  • 2
  • 8
  • 26
0

You can show the index right underneath the searchbar rather than having it display where the search cancel button goes by default.

pkaur
  • 95
  • 1
  • 7