1
所以我的代碼如下:添加自定義的UIButton到UINavigationBar的
// Create a containing view to position the button
UIView *containingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 23.5, 21.5)] autorelease];
// Create a custom button with the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Settings.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(settings) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(-19, -3, 21.5, 21.5)];
[containingView addSubview:button];
// Create a container bar button
UIBarButtonItem *containingBarButton = [[[UIBarButtonItem alloc] initWithCustomView:containingView] autorelease];
self.navigationItem.rightBarButtonItem = containingBarButton;
的問題是,我Settings.png原始圖像尺寸是21.5,21.5和有脫穎而出的按鈕是點擊超級難。爲了觸發UITouchUpInside被觸發,我必須非常努力。如果我將它放入應用商店,這顯然會被拒絕,因爲它不符合蘋果的HIG。有沒有解決的辦法?我仍然需要使用UIView作爲UIButton的容器,因爲我想將它正確地放置在UINavigationBar上