首页 > 其他 > 详细

UISearchBar的使用

时间:2016-04-05 12:21:35      阅读:287      评论:0      收藏:0      [点我收藏+]
    self.searchBar = [[UISearchBar alloc] init];
    self.searchBar.barTintColor = BLUE_COLOR;
1.0 更改背景色 / 添加边框 / 
    UIView *searView = [[self.searchBar.subviews firstObject].subviews lastObject];
    searView.backgroundColor = BLUE_COLOR;
    self.searchBar.layer.cornerRadius = 10;
    self.searchBar.layer.masksToBounds = YES;
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 255.0/255.0, 255.0/255.0, 255.0/255.0, 1 });
    CGColorSpaceRelease(colorSpace2);
    [self.searchBar.layer setBorderColor:colorref2];//边框颜色
    [self.searchBar.layer setBorderWidth:0.5];//边框宽度
    CGColorRelease(colorref2);
    self.searchBar.placeholder = @"查找公司";
2.0 遍历更换 放大镜 和 占位文字颜色
    for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) {
       
        if ([subview isKindOfClass:[UITextField class]]) {
            UITextField *textField = (UITextField*)subview;
           
//            textField.textColor = [UIColor redColor];                         //修改输入字体的颜色
//            [textField setBackgroundColor:[UIColor grayColor]];      //修改输入框的颜色
            [textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];   //修改placeholder的颜色
            UIImage *image = [UIImage imageNamed:@"minge_edit"];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
            [textField setLeftView:imageView];
        } else if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
        {
            [subview removeFromSuperview];
        }
    }
    [self addSubview:self.searchBar];

UISearchBar的使用

原文:http://www.cnblogs.com/yangdeming/p/5354183.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!