您当前的位置: 首页 >  ar

培根芝士

暂无认证

  • 3浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

UISearchBar设置背景色和输入框色

培根芝士 发布时间:2014-11-08 19:43:22 ,浏览量:3

设置背景色

将颜色转为图片

- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
    UIGraphicsBeginImageContext(size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

将颜色转成的Image设置为UISearchBar的背景图片

searchBar.backgroundImage = [self imageWithColor:barBackColor size:CGSizeMake(1, 1)];
设置输入框色

首先需要获取UISearchBar的输入框控件

- (UITextField *)getTextField {
    if (@available(ios 13.0,*)) {
        return [searchBar valueForKey:@"searchField"];
    }
    else {
        return [searchBar valueForKey:@"_searchField"];
    }
}

设置输入框背景色

UITextField *searchTextField = [self getTextField];
searchTextField.backgroundColor = textBackColor;

 

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.0400s