美文网首页
UISearchBar 设置背景透明色

UISearchBar 设置背景透明色

作者: 世玉茹花 | 来源:发表于2019-11-18 17:23 被阅读0次

    简单记录一下,,,

      UIImage* searchBarBg = [self GetImageWithColor:[UIColor clearColor] andHeight:20.0f];
        [_searchBar setBackgroundImage:searchBarBg];
        [_searchBar setBackgroundColor:[UIColor clearColor]];
        [_searchBar setSearchFieldBackgroundImage:searchBarBg forState:UIControlStateNormal];
    
    - (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
    {
        CGRect rect = CGRectMake(0, 0, size.width, size.height);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        
        return image;
    }
    

    相关文章

      网友评论

          本文标题:UISearchBar 设置背景透明色

          本文链接:https://www.haomeiwen.com/subject/vopbictx.html