开发者

how to add 4 buttons in UInav bar for iphone

i want to add开发者_C百科 4 buttons in UINAV bar how to do that should i make them in UINAVBAR controller or navItem or UIBarbutton???

any code will be appreciated Thanks


UINavigationBar is used to navigate backward or forward in application. You can't use it for any other functionality. How ever if you want to show four button on top use UIToolBar. A tool bar can multiple button with different functionality.

` create toolbar using new

    toolbar = [UIToolbar new];
    toolbar.barStyle = UIBarStyleDefault;
    [toolbar sizeToFit];
    toolbar.frame = CGRectMake(0, 410, 320, 50);

    //Add buttons
    UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                                 target:self
                                                                                 action:@selector(pressButton1:)];

    UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                                                 target:self
                                                                                 action:@selector(pressButton2:)];

    UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
    target:self action:@selector(pressButton3:)];

    //Use this to put space in between your toolbox buttons
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
    target:nil
    action:nil];

    //Add buttons to the array
    NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil];

    //release buttons
    [systemItem1 release];
    [systemItem2 release];
    [systemItem3 release];
    [flexItem release];

    //add array of buttons to toolbar
    [toolbar setItems:items animated:NO];

    [self.view addSubview:toolbar];`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜