iOS8,遍历seachBar 得不到textfield了 就意味着之前的方法通通不能用了.
mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(5, 28, self.navView.width - 70, 30)];
mySearchBar.delegate = self;
mySearchBar.showsCancelButton = NO;
mySearchBar.backgroundImage = [ComponentFactory getCreateImageWithColor:[UIColor clearColor]];// 这个方法可以替换背景图
mySearchBar.barStyle = UIBarStyleDefault;
mySearchBar.backgroundColor = [UIColor getColor:@"#ededed"];
[mySearchBar setSearchFieldBackgroundImage:[ComponentFactory getSearchBarBackgroundImageWithColor:[UIColor getColor:@"#ededed"]] forState:UIControlStateNormal];
mySearchBar.layer.borderWidth = 0;
mySearchBar.layer.cornerRadius =2;
mySearchBar.layer.borderColor = [UIColor clearColor].CGColor;
mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
mySearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ (UIImage *)getSearchBarBackgroundImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 44.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}