【问题标题】:Customize UISearchDisplayController自定义 UISearchDisplayController
【发布时间】:2009-10-13 11:35:31
【问题描述】:

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

以下对象可以自定义吗?

1. UISearchBar 范围按钮 (UISegmentedController)

2。 UIResultsTableView

3.键盘(至少它是黑色的)

【问题讨论】:

  • 你用什么来生成它:笔尖还是代码?
  • 我正在使用代码。我能够自定义所有内容,因此感谢大家的帮助,但是我无法删除问题。

标签: iphone customization uisearchdisplaycontroller


【解决方案1】:

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

我能够通过某种 hack 代码更改分段控件:

- (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】:

    尽管尝试了每个分段控制样式,但我也始终无法让按钮变小。这是我需要用来至少在 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】:

      我可以使用以下代码自定义表格视图:

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

      但是,当您触摸取消按钮时,界面会在返回原始 tableview 之前闪烁白色。如何解决这个问题?

      【讨论】:

      • 我不得不从您的帖子中删除图片,因为 ImageShack 已将其删除并替换为广告。请参阅meta.stackexchange.com/q/263771/215468 了解更多信息。如果可能,您最好重新上传它们。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多