UIToolBar background transparent

倖福魔咒の 提交于 2019-12-03 21:24:53

Not sure what you're after here, but your code is messy, and I think you can get what you want without so much effort. Anyway, a button item should not have a toolbar as its custom view.

If your goal is to have a 'prev' button on the left and a 'next' button on the right of a UINavigationBar, then you can just set them as the UINavigationItem's leftBarButtonItem and rightBarButtonItem. No array necessary.

If your goal is to have 'prev' and 'next' adjacent to each other and on the right side of the UINavigationBar, then put them ('next' first) in an array and then use UINavigationItem's setRightBarButtonItems:animated:.

In neither case is a UIToolbar necessary. You can couple a UIToolbar with a UINavigationController as per Apple's docs here. It pops up at the bottom of the screen, perhaps not what you want, but you can set its tint or background image. If you must have the toolbar at top, you can create one and place it there manually, not too hard.

Good luck!

To make a toolbar transparent, use the following:

const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];

[self.toolbar setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

set toolbarStyle -1 like this

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