允许UIBarButtonItem触摸UINavigationBar的顶部和底部

问题描述

|| 看看Droplr iPhone应用程序: 注意“ 0”如何能够触摸屏幕/导航栏的右,左,上和下? 我怎样才能取得类似的成绩?这是我制作示例UIBarButton并将其设置为正确项目的方法
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setimage:image forState:UIControlStatenormal];    
button.frame= CGRectMake(0.0,0.0,image.size.width,image.size.height);
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *bb = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease];
[self.navigationItem setRightBarButtonItem:bb animated:YES];
但是,它没有正确对齐,并且在顶部和底部之间有相当大的余量。我的图片大小是正确的(44px),看起来像将其缩小以适合各种框架。 那么,我该怎么做呢? 编辑:糟糕,顶部/底部的间距是我的错。但是,我不知道如何将条形按钮与左侧/右侧对齐。这就是我的意思:(抱歉按钮很难看,这只是一个测试) 我尝试设置图像插入,但是似乎没有任何作用。     

解决方法

        
UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(0,30,30)];



UIButton *searchbutton = [[UIButton alloc] initWithFrame:CGRectMake(2,2,50,30)];
[searchbutton setImage:[UIImage imageNamed:@\"some-pic.png\"] forState: UIControlStateNormal];
[rightview addSubview:searchbutton];


UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:rightview];
self.navigationItem.rightBarButtonItem = customItem;
[customItem release];
我为rightBarButtonItem使用customView,并使其正确对齐。 只需尝试使用CGRectMake-Numbers作为x坐标,以测试我添加到高数字中的情况...