我創建了一個自定義按鈕並將其應用於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