Saturday, March 3, 2012

Custom navigation bar and toolbar

The below code can custom the font type on the navigation bar, make both navigation bar and toolbar to be translucent style, set up the left button to be "Back" in the next view.

// set navigation bar to be translucent style
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
// set custom font and size in the navigation bar
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
    label.font = [UIFont fontWithName:@"Marker Felt" size: 22.0];
    label.BackgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.text = self.title;
    [self.navigationController.navigationBar.topItem setTitleView:label];
    [label release];
// set the left button to be "Back"
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = backBtn;
    [backBtn release];

// set toolbar to be translucent style
    myToolbar.barStyle = UIBarStyleDefault;
    myToolbar.tintColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    myToolbar.translucent = YES;

No comments:

Post a Comment