How to make UIToolbar have a Clear Background?

前端 未结 8 1829
渐次进展
渐次进展 2021-02-05 12:54

I have a UIToolbar that has a white tint, with a bar button item, followed by some flexible space, followed by another bar button item. I would like to make the toolbar complete

相关标签:
8条回答
  • 2021-02-05 13:22

    Hacky, sorry, but the only way I've found so far that reliably works in both iOS 7 and iOS 6 is to do this:

    [[toolbar.subviews objectAtIndex:0] removeFromSuperview];
    
    0 讨论(0)
  • 2021-02-05 13:30

    If you want a global solution take advantage of the UIAppearance proxy:

    UIToolbar *toolbarAppearance = [UIToolbar appearance]; [toolbarAppearance setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

    0 讨论(0)
  • 2021-02-05 13:31

    Swift 3 version of accepted answer:

       self.toolbar.isTranslucent = true
        self.toolbar.setBackgroundImage(UIImage(),
                                   forToolbarPosition: UIBarPosition.any,
                                   barMetrics: UIBarMetrics.default)
    
        self.toolbar.setShadowImage(UIImage(), forToolbarPosition: UIBarPosition.any)
    
    0 讨论(0)
  • 2021-02-05 13:39
    [self.toolbar setBackgroundImage:[UIImage new]
                  forToolbarPosition:UIToolbarPositionAny
                          barMetrics:UIBarMetricsDefault];
    
     [self.toolbar setBackgroundColor:[UIColor clearColor]];
    
    0 讨论(0)
  • 2021-02-05 13:45

    Subclass UIToolbar, and implement the below method:

    - (void)drawRect:(CGRect)rect 
    {
      [[UIColor colorWithWhite:0 alpha:0.6f] set]; // or clearColor etc
      CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
    }
    

    see more details here

    0 讨论(0)
  • 2021-02-05 13:45

    set toolbarStyle -1 like this

     tools.barStyle = -1; // clear background
    
    0 讨论(0)
提交回复
热议问题