0

我在导航控制器中的 uibutton 和 uibutton 上看到了很多帖子,但我的问题是 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];

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

4

2 回答 2

1
    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];
于 2012-06-15T08:06:47.110 回答
0

尝试这个

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

现在将您创建的 barbuttonItem 设置为项目的 rightBarButtonItem,

item.rightBarButtonItem = button; 

它对我有用。

于 2015-03-12T09:44:39.780 回答