【问题标题】:Cant set color in searchbar of Searchbar display Controller无法在搜索栏显示控制器的搜索栏中设置颜色
【发布时间】:2014-08-06 04:21:13
【问题描述】:
UISearchBar *searchBar = [[UISearchBar alloc] init];

[searchBar setTranslucent:NO];


searchBar.barTintColor=[UIColor colorWithRed:92.0/255.0 green:122.0/255.0 blue:178.0/255.0 alpha:1.0];

searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);


self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar
                                                                     contentsController:self];

 self.searchDisplayController.searchResultsDelegate = self;

 self.searchDisplayController.searchResultsDataSource = self;


 self.searchDisplayController.delegate = self;

在上面的代码中,我想在 SearchBarDisplay Controller 的搜索栏中设置颜色,但我无法正确设置...请告诉我解决方案...谢谢

【问题讨论】:

    标签: ios iphone ios7 uisearchbar


    【解决方案1】:

    您应该可以设置背景图片来自定义搜索文本字段背景:

    - (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
    

    https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBar_Class/Reference.html#//apple_ref/occ/instm/UISearchBar/searchFieldBackgroundImageForState:

    【讨论】:

      【解决方案2】:

      试试这个:

         [sBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_bar"] forState:UIControlStateNormal];
      
         [sBar setBackgroundImage:[UIImage imageNamed:@"search_bar_bg"]];
      
         [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor] ];
      

      【讨论】:

        猜你喜欢
        • 2014-01-30
        • 1970-01-01
        • 2016-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多