uibarbutton 项未显示 uibutton



我在导航控制器的uibutton和uibutton上看到了很多SO中的帖子不起作用,但我的问题是uibutton出现在导航控制器上的视图中,这是我的代码

showMeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
showMeButton.frame = CGRectMake(0, 50, 100, 40);
[showMeButton setTitle:@"User Avtar" 
              forState:UIControlStateNormal];
[showMeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:showMeButton];
[showMeButton addTarget:self action:@selector(showMeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

为什么这行代码不起作用self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:showMeButton];

请帮帮我...提前致谢:):)

    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button1 setFrame:CGRectMake(00,15,50,26)];
    [button1 setTitle:@"User Avtar" forState:UIControlStateNormal];
    button1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    [self.navigationController.navigationBar addSubview:button1];

试试这个

UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
UINavigationItem *item = [navigationBar.items lastObject]; 

现在将您创建的栏按钮项设置为项目的右侧栏按钮项,

item.rightBarButtonItem = button; 

它对我有用。

最新更新