как отобразить изображение в правом углу навигационной панели? - PullRequest
0 голосов
/ 09 октября 2010

Я хочу отобразить изображение на панели навигации в правом углу. Некоторые, пожалуйста, скажите мне, как я могу это сделать. Я попытался, взяв uiimageview в правом углу панели навигации, но не получил его. Заранее спасибо

1 Ответ

0 голосов
/ 09 октября 2010

A UINavigationItem (то, что вы хотите использовать здесь) имеет rightBarButtonItem, который вы можете установить.

Сделайте что-то вроде этого:

UIBarButtonItem *rightCornerButton = [[UIBarButtonItem alloc] 
                initWithImage:[UIImage imageNamed:@"myAwesomeImage.png"] 
                style:UIBarButtonItemStylePlain target:self 
                action:@selector(functionYouWantToRunWhenBarButtonIsPressed)];
[self.navigationItem setRightBarButtonItem:rightCornerButton];
// If you do it this way, the button will disappear when you call -pushViewController on your navigationController.
[rightCornerButton release];

Или еще лучше (снимая рамку вокруг):

UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barButton setImage:[UIImage imageNamed:@"reload1.png"] forState:UIControlStateNormal];
UIBarButtonItem *rightCornerButton = [[UIBarButtonItem alloc] initWithCustomView:barButton];
[rightCornerButton setTarget:self];
[rightCornerButton setAction:@selector(functionYouWantToRunWhenBarButtonIsPressed)];
[self.navigationItem setRightBarButtonItem:rightCornerButton];
// If you do it this way, the button will disappear when you call -pushViewController on your navigationController.
[rightCornerButton release];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...