PDA

View Full Version : Navigation text control (iphone)




johnellisdm
Apr 2, 2008, 06:44 PM
i am trying to write a feature that will allow me to have a search text box that drops down from the navigation bar like the search bar does in safari for the iphone.

i'm very new to objective c and mac programming, but i'm able to get along great by looking at examples. unfortunately, there isn't an example for how to do this. any help or pointers would be appreciated.



johnellisdm
Apr 3, 2008, 12:54 AM
nevermind, i went a different direction. i just put a text area in the custom right view of the nav bar like this:


UINavigationItem *navItem = self.navigationItem;
CGRect newFrame = CGRectMake(0, 0, 220, 25);
UITextField *textField = [[UITextField alloc] initWithFrame:newFrame];

textField.borderStyle = UITextFieldBorderStyleRounded;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont systemFontOfSize:17.0];
textField.placeholder = [self searchPlaceholder];
textField.backgroundColor = [UIColor clearColor];
textField.delegate = self;

textField.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textField.returnKeyType = UIReturnKeyDone;

textField.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right

UIImageView *searchIconView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,25,25)];
searchIconView.image = [UIImage imageNamed:@"search.png"];
textField.leftView = searchIconView;
[searchIconView release];
textField.leftViewMode = UITextFieldViewModeAlways;

navItem.customRightView = textField;
[textField release];



this actually fits my situation better as i didn't really have an important title in the nav bar and i never have a "back" button where the search is taking place.