2011-10-09 69 views
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上

回答

0

尝试设置一个更大的fram到像40,40这样的按钮,并将内容模式设置为中心所以图像将成为中心。

button.contentMode = UIViewContentModeCenter;

告诉我,如果这有助于

相关问题