iphone - How can I use an UIBarButtonItem style without the UIToolBar

非 Y 不嫁゛ 提交于 2019-12-06 00:31:23

there is a cheeky hack that will help you with this.

you want to use a UISegmentedControl with style set to UISegmentedControlStyleBar and only one item. You also need to setMomentary to yes - to make it behave like a button:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];

This will give you a button that looks like a UIBarButtonItem that you can add to your normal view as if it were a button. You can add a target and an action as well. :)

This is what you get: something like this:

I haven't exactly done anything like that, but I suggest you could somehow set all the UIToolBar's subviews alpha to zero except for the UIBarButtonItem . Just leave the UIBarButtonItem visible.

UIToolBar inherits from UIView, so my first try would be to set its backgroundColor to clearColor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!