iOS UISearchBar 属性 设置详解

来源:互联网 发布:cnc编程代码 编辑:程序博客网 时间:2024/06/07 01:03
[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; 

0 0