我想在导航栏上绘制自定义按钮。
任何人都可以帮助我。
答案 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];