嗨!我使用过UIBarButton Image但是我有这样的问题。我的意思是背面的图像+按钮。因为我已经编写了下面的代码。
UIBarButtonItem * btnMap = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@“mapbutton.png”] style:UIBarButtonItemStylePlain target:self action:@selector(btnMapClicked :)]; self.navigationItem.rightBarButtonItem = btnMap; [btnMap发布];
答案 0 :(得分:1)
使用initWithCustomView并将UIButton设置为customView:
UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
subBtn.frame = CGRectMake(0, 0, 50, 40); //adjust as needed
[subBtn setImage:[UIImage imageNamed:@"mapbutton.png"] forState:UIControlStateNormal];
[subBtn addTarget:self action:@selector(btnMapClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithCustomView:subBtn];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
请注意,btnMapClicked:中的发件人现在将是UIButton而不是UIBarButtonItem。