Customize UISearchDisplayController

后端 未结 3 748
后悔当初
后悔当初 2021-02-06 13:08

alt text http://img210.imageshack.us/img210/5992/searchdisplaycontroller.png

Are the following objects customizable?

1. UISearchBar Scope Buttons (UISegm

相关标签:
3条回答
  • 2021-02-06 13:35

    alt text http://img527.imageshack.us/img527/9775/searchdisplaycontrollerz.png

    I was able to change the segmented control by a sort-of hack code:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    for (UIView *subview in self.view.subviews) {
        for (UIView *subview2 in subview.subviews) {
            if ([subview2 isKindOfClass:[UISegmentedControl class]]) {
                UISegmentedControl *segmentedControl = (UISegmentedControl *)subview2;
                segmentedControl.tintColor = [UIColor blackColor];
                segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
            }           
        }
    }}
    

    However the buttons are HUGE, how could I fix it so they are just as pretty as the original?

    0 讨论(0)
  • 2021-02-06 13:36

    I was able to customize the tableview by using the following code:

    - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {
    tableView.backgroundColor = [UIColor colorWithRed:(19.0 / 255.0) green:(19.0 / 255.0) blue:(19.0 / 255.0) alpha:1.0];
    tableView.separatorColor  = [UIColor blackColor]; }
    

    However when you touch the cancel button, the interface will flash white before going back to the original tableview. How can this be fixed?

    0 讨论(0)
  • 2021-02-06 14:00

    I was also never able to get the buttons to be smaller despite trying every segmentedControlStyle. Here's the code I needed to use to at least get the tint color correct on IOS4:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
        static BOOL tintAlreadyChanged = NO;
        if (tintAlreadyChanged) return;
    
        NSLog(@"Searching subViews for UISegmentControl:");
        //fix segmented control
        for (UIView *subview in self.view.subviews) {
            //NSLog(@"\n\nsubView = %@",subview);
            for (UIView *subview2 in subview.subviews) {
                //NSLog(@"subView2 = %@",subview2);
                for (UIView *subview3 in subview2.subviews) {
                    //NSLog(@"subView3 = %@",subview3);
                    if ([subview3 isKindOfClass:[UISegmentedControl class]]) {
                        NSLog(@"Found UISegment SubView = %@",subview3);
                        UISegmentedControl *segmentedControl = (UISegmentedControl *)subview3;
                        segmentedControl.tintColor = [UIColor blackColor];
                        segmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
                        tintAlreadyChanged = YES;
                    }
                }                       
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题