Remove or override the “Clear Button” on UISearchDisplayController in a UIPopoverController on iPad?

后端 未结 1 1313
半阙折子戏
半阙折子戏 2021-01-26 05:01

When using UISearchDisplayController with a UISearchBar in iPad it is displayed in a UIPopoverController. I would like to override the clear button as shown on the image to make

相关标签:
1条回答
  • 2021-01-26 05:26

    i did that once .. i replace the clear button with a custom button to make a custom action .. please check this

    UISearchBar *searchBar = yourSearchController.searchBar;
    UITextField *searchtextfield = [searchBar.subviews objectAtIndex:1];
    UIButton *cButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cButton.frame = CGRectMake(0, 0, 20 , 20);
    cButton.backgroundColor = [UIColor clearColor];
    [cButton setImage:[UIImage newImageFromResource:@"yourButtonImage"] forState:UIControlStateNormal];//your button image.
    cButton.contentMode = UIViewContentModeScaleToFill;
    [cButton addTarget:self action:@selector(customButtonPressed) forControlEvents:UIControlEventTouchUpInside];//This is the custom event
    [searchtextfield setRightView:cButton];
    [searchtextfield setRightViewMode:UITextFieldViewModeAlways];
    

    Good luck.

    0 讨论(0)
提交回复
热议问题