我创建了一个自定义按钮并将其应用于UIbarbuttonitem。 没有错误,但没有显示在导航栏:( 上这是我的代码 -如何将图像添加到UIBarButtonItem?
//create a custom button
UIImage *image = [UIImage imageNamed:@"TESTButton.png"];
UIButton *myCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
myCustomButton.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
[myCustomButton setImage:image forState:UIControlStateNormal];
[myCustomButton addTarget:nil action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myCustomButton];
self.navigationItem.leftBarButtonItem = button;
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
[button release];
[myCustomButton release];
[image release];
[navID release];
如果谁可以解决我的代码?:)
这样? UIBarButtonItem \t * button = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(goBack :)]; Stil不工作..没有错误,但没有显示:( – Leanne
请确保您的图像不返回为零 – DexterW
啊nvm,它工作:) thanx堆! – Leanne