我尝试使用UIBarButtonItem
设置image
。问题是它永远不会出现。当我只添加一个UIBarButtonItem
title
时就可以了。
UIBarButtonItem *openLeftSliderButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"filter.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openLeftSlider)];
self.navigationItem.leftBarButtonItem = openLeftSliderButton;
答案 0 :(得分:1)
UIImage *sideImage = [UIImage imageNamed:@"i1.jpg"];
UIButton *btnSideMenu = [UIButton buttonWithType:UIButtonTypeCustom];
[btnSideMenu setImage:sideImage forState:UIControlStateNormal];
[btnSideMenu setImage:sideImage forState:UIControlStateHighlighted];
[btnSideMenu setFrame:CGRectMake(0, 0, 20, 20)];
[btnSideMenu addTarget:self action:@selector(btnLeftMenuClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *sideMenuItem = [[UIBarButtonItem alloc] initWithCustomView:btnSideMenu];
self.navigationItem.leftBarButtonItem=sideMenuItem;