我应该如何在导航栏上绘制自定义按钮

时间:2010-10-06 11:12:43

标签: iphone objective-c uinavigationbar

我想在导航栏上绘制自定义按钮。

任何人都可以帮助我。

3 个答案:

答案 0 :(得分:5)

简单

[[UIBarButtonItem alloc] initWithCustomView: customButton];

将起作用

这样的事情:

UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"animage.png"]];
[button addTarget:self action:@selector(onClick:) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView: button];
[self.navigationItem setLeftBarButtonItem:customItem];

干杯, KrzysztofZabłocki

答案 1 :(得分:3)

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"DontWorryAboutThis" style:UIBarButtonItemStylePlain target:self action:@selector(method:)];
[barButton setImage:[UIImage imageNamed:@"animage.png"]];
[self.navigationItem setLeftBarButtonItem:barButton];

答案 2 :(得分:0)

      UIBarButtonItem *btn=[[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(btnPressed)];
      [self.navigationItem setRightBarButtonItem:btn];