修改UISearchDisplayController的searchBar的cancel按鈕文字為中文"取消" 設置statusBar的背景色和searchBar背景色一致

bug.gif

]initWithFrame:CGRectMake(0, 0, VGScreenW, 20)];
//默認讓imageViewStatus隱藏
_imageViewStatus.hidden = YES;
}
return _imageViewStatus;
}

  • (void)initSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64)];
    self.searchBar.backgroundImage = [UIImage imageFormColor:[UIColor clearColor] frame:CGRectMake(0, 0, VGScreenW, 64)];
    self.searchBar.barStyle = UIBarStyleDefault;
    self.searchBar.backgroundColor = [UIColor clearColor];
    [self.searchBar setBarTintColor:[UIColor colorWithWhite:0.9 alpha:0]];
    self.searchBar.translucent = YES;
    self.searchBar.delegate = self;
    self.searchBar.placeholder = TipPlaceHolder;
    self.searchBar.keyboardType = UIKeyboardTypeDefault;
    [self.mapView addSubview:self.searchBar];
    }
    //
  • (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    controller.searchBar.backgroundColor = [UIColor whiteColor];
    controller.searchBar.showsCancelButton = YES;
    self.imageViewStatus.backgroundColor = [UIColor redColor];
    self.imageViewStatus.hidden = NO;//設置imageViewstatus顯示
    [self.imageViewStatus setImage:[UIImage imageNamed:@"statusBarView"]];
    [self.navigationController.navigationBar.window addSubview:self.imageViewStatus];
    [self.navigationController.navigationBar.window bringSubviewToFront:self.imageViewStatus];
    for (id searchbutton in controller.searchBar.subviews) {
    UIView *view = (UIView *)searchbutton;
    UIButton *cancelButton = (UIButton *)[view.subviews objectAtIndex:2];
    cancelButton.enabled = YES;
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];//文字
    [cancelButton setTitleColor:VGColor(255, 150, 0) forState:UIControlStateNormal];
    break;
    }
    }
    //點擊取消按鈕時設置imageViewStatus隱藏
  • (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    self.imageViewStatus.hidden =YES;
    }
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • 轉自:http://www.code4app.com/blog-866962-1317.html1、設置UILab...
    MMOTE閱讀 1,890評論 1 1
  • //設置尺寸為屏幕尺寸的時候self.window = [[UIWindow alloc] initWithFra...
    LuckTime閱讀 975評論 0 0
  • 作者唯一QQ:228544117。。。。。 =========后面的都要新建一個文章 AppDelegate.h ...
    CC_iOS閱讀 1,185評論 0 0
  • 1、設置UILabel行間距 NSMutableAttributedString* attrString = [[...
    十年一品溫如言1008閱讀 2,033評論 0 3
  • 喜歡攝影,對它的熱愛超乎想象, 喜歡記錄,暫停生活中的每一瞬間, 喜歡時間,現(xiàn)在二十三點十四分, ...
    zy不變閱讀 199評論 0 4

友情鏈接更多精彩內容