8
我添加自定義按鈕,導航控制器導航控制器添加自定義按鈕無邊框
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)]; self.navigationItem.leftBarButtonItem = backButton;
它工作正常,但按鈕顯示爲界。我該如何解決這個問題?
UPDATE 我找到了解決方案
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; [button setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonFavoriteClicked) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:button]; [button release];
self.navigationItem.leftBarButtonItem = back;