代码之家  ›  专栏  ›  技术社区  ›  Mark

自定义UISearchDisplayController

  •  5
  • Mark  · 技术社区  · 16 年前

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

    1UISearchBar范围按钮(UISegmentedController)

    2UIResultsTableView

    三。键盘(至少是黑色)

    3 回复  |  直到 16 年前
        1
  •  3
  •   Mark    16 年前

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

    我可以通过一种黑客代码来改变分段控制:

    - (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;
            }           
        }
    }}
    

    不管这些按钮有多大,我怎么能把它修好,让它们和原来一样漂亮呢?

        2
  •  1
  •   DoctorG    15 年前

    尽管我尝试了每种分段控制方式,但我还是无法使按钮变小。下面是我需要使用的代码,至少要在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;
                    }
                }                       
            }
        }
    }
    
        3
  •  1
  •   Undo ptrk    10 年前

    - (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]; }