如何让UIBarButtonItem隐形但有效?

时间:2013-06-06 06:04:23

标签: ios

我有这个方法返回UIBarButtonItem,我想要隐形按钮但是当有人点击那个时起作用,,,,,

- (UIBarButtonItem *)leftMenuBarButtonItem {

UIBarButtonItem *barbuttonitem = [[UIBarButtonItem alloc]
                                  initWithImage:[UIImage imageNamed:@"bacbbutton.png"] style:UIBarButtonItemStyleDone
                                  target:self
                                  action:@selector(leftSideMenuButtonPressed:)];


return barbuttonitem;
}

如何使此按钮不可见,但每当使用时单击该角或导航栏,按钮就会生效,但隐藏可见性......

2 个答案:

答案 0 :(得分:1)

将按钮设置为hidden将意味着无法点按该按钮。您只想将其设置为透明。您需要通过创建带有自定义视图的条形按钮项并将视图alpha设置为零来完成此操作。自定义视图将为UIButton

答案 1 :(得分:1)

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"bacbbutton.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(leftSideMenuButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
btn.alpha = 0.3;
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithCustomView:btn];