[self.view setBackgroundColor:[UIColor colorWithRed:239.0/255 green:239.0/255 blue:239.0/255 alpha:1.0f]];
MySearchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0, 65, width, 45)];
MySearchBar.delegate = self;
MySearchBar.barStyle=UIBarStyleDefault;
MySearchBar.placeholder=@"Search";
[MySearchBar setShowsCancelButton:NO];//显示右侧取消按钮
MySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;
float version = [[[ UIDevice currentDevice ] systemVersion ] floatValue ];
// theTableView.tableHeaderView = searchBar;
if ([ MySearchBar respondsToSelector : @selector (barTintColor)]) {
float iosversion7_1 = 7.1 ;
if (version >= iosversion7_1)
{
//iOS7.1
[[[[ MySearchBar . subviews objectAtIndex : 0 ] subviews ] objectAtIndex : 0 ] removeFromSuperview ];
[ MySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
else
{
//iOS7.0
[ MySearchBar setBarTintColor :[ UIColor clearColor ]];
[ MySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
}
else
{
//iOS7.0 以下
[[ MySearchBar.subviews objectAtIndex : 0 ] removeFromSuperview ];
[ MySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
[self.view addSubview:MySearchBar];
searchBar.searchBarStyle =UISearchBarStyleMinimal;