Transparent UIToolbar

前端 未结 7 1309
萌比男神i
萌比男神i 2021-02-14 19:42

I wrote the following code to make my toolbar transparent.

[mtoolbar setBackgroundColor:[UIColor clearColor]];

How do I make UIToolbar

7条回答
  •  清酒与你
    2021-02-14 19:52

    Setting the property translucent to YES will not work in iOS 5 and below. Here's how it can be done without subclassing toolbar:

    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];
    

提交回复
热议问题