Navigation text control (iphone)

Discussion in 'Mac Programming' started by johnellisdm, Apr 2, 2008.

  1. johnellisdm macrumors member

    Feb 21, 2007
    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.
  2. johnellisdm thread starter macrumors member

    Feb 21, 2007
    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.

Share This Page