相关疑难解决方法(0)

以编程方式将导航栏添加到导航栏

嗨,我需要在导航栏中以编程方式设置右侧的按钮,这样如果我按下按钮,我将执行一些操作.我以编程方式创建了导航栏;

navBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0,0,320,44) ];
Run Code Online (Sandbox Code Playgroud)

同样,我需要在此导航栏的右侧添加按钮.为此我用过,

1.  

    UIView* container = [[UIView alloc] init];

    // create a button and add it to the container
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 130, 44.01)];
    [container addSubview:button];
    [button release];

    // add another button
    button = [[UIButton alloc] initWithFrame:CGRectMake(160, 0, 50, 44.01)];
    [container addSubview:button];
    [button release];

    // now create a Bar button item
    UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];

    // set the nav bar's right button item
    self.navigationItem.rightBarButtonItem = item;
    [item release];
Run Code Online (Sandbox Code Playgroud)

2.   …

iphone objective-c uinavigationbar uibarbuttonitem

87
推荐指数
6
解决办法
15万
查看次数