iOS设置tabbar顶部横线阴影效果

2018-06-23  本文已影响0人  研发组的小仙女

直接上代码

//设置tabbar顶部line阴影  

UIImage * image = [self imageWithColor:[UIColor blackColor] size:CGSizeMake(gScreenWidth, 0.7)];

[self.tabBar setShadowImage:image];

 self.tabBar.layer.shadowColor = [UIColor blackColor].CGColor;    

self.tabBar.layer.shadowOffset = CGSizeMake(0, -3);    

self.tabBar.layer.shadowOpacity = 0.25; 

- (UIImage*)imageWithColor:(UIColor*)color size:(CGSize)size {

    if(!color || size.width<=0|| size.height<=0)returnnil;

   CGRectrect =CGRectMake(0.0f,0.0f, size.width, size.height);

    UIGraphicsBeginImageContextWithOptions(rect.size,NO, 0);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, color.CGColor);

    CGContextFillRect(context, rect);

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnimage;

}

上一篇 下一篇

猜你喜欢

热点阅读