码迷,mamicode.com
首页 > 其他好文 > 详细

UISearchBar的使用

时间:2016-04-05 12:23:54      阅读:129      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!