【问题标题】:UIToolbar in iPadiPad 中的 UIToolbar
【发布时间】:2010-11-27 02:12:56
【问题描述】:

我想在导航栏的两端(在 iPad 的 Detail View Controller 中)有两个按钮。

所以我创建了两个 UIToolbars 并将它们设置为 Left&RightBarButtonItems。

但是,导航栏有一些颜色变化。

附上图片供您理解。

我使用的代码,

 UIToolbar *leftToolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
 NSMutableArray *lItems = [[NSMutableArray alloc] initWithArray:[leftToolbar items]];
 UIBarButtonItem *lb1 =[[UIBarButtonItem alloc]initWithTitle:@"Home"style:UIBarButtonItemStyleBordered target:self action:@selector(home:) ];

 UIBarButtonItem *lb2 =[[UIBarButtonItem alloc]initWithTitle:@"New Document"style:UIBarButtonItemStyleBordered target:self action:@selector(newDoc:) ];

 [lItems insertObject:lb1 atIndex:0];
 [lItems insertObject:lb2 atIndex:1];
 [leftToolbar setItems:lItems animated:YES];
 [lItems release];



  leftToolbar.barStyle =UIBarStyleBlackTranslucent;
 leftToolbar.tintColor=[UIColor clearColor];
 self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:leftToolbar];

你能帮我避免这种颜色变化吗?

有没有其他方法可以在不使用 UIToolbar 的情况下拥有这样的按钮?

谢谢,

戈皮。

【问题讨论】:

    标签: ipad


    【解决方案1】:

    只是去掉导航栏和添加工具栏,为什么要在导航栏上添加工具栏?

    【讨论】:

    • 我需要显示一些文档,所以我需要在导航栏的标题中显示文档的名称。
    • 如何在工具栏中添加标题?我相信我不能在工具栏中有标签。我找不到任何其他方法来实现它。如果我错过了什么,请告诉我。谢谢 GameBit。
    • 这里有 2 个选择:1) 只需将 UILabel 放在顶部 2) 以普通样式添加 UITabButton
    • 为什么不能添加UILabel?只是 [_toolbar addSubview:...] 就是这样(不要在 IB 中这样做)。
    • 为什么它不是工具栏的一部分? UILabel *titleLabel = [[UILabel alloc] initWithFrame:[toolBar bounds]]; [titleLabel setTextAlignment:UITextAlignmentCenter]; [titleLabel setBackgroundColor:[UIColor clearColor]]; [titleLabel setText:@"我的标题"]; [工具栏 addSubview:titleLabel]; [titleLabel 发布];
    【解决方案2】:

    为了达到同样的效果,使用段控制,在左或右barbutton的视图中设置它,一旦你选择一个段,几秒钟后取消选择它,比如0.3秒,它看起来不错,没有颜色变化,它看起来像一个零件导航栏的

    【讨论】:

      【解决方案3】:

      找到解决方案! 代码是正确的,但有一个小错误。必须将高度设置为 44,而不是 45。我这样做了,它似乎适合现有的 NavigationBar。

      UIToolbar *leftToolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
      

      为我工作。 .无论如何,我转向了单一工具栏方法。

      希望这对某人有所帮助。!!

      祝你有美好的一天!

      戈皮。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-21
        • 1970-01-01
        • 2011-05-18
        • 2010-11-07
        • 2010-12-31
        相关资源
        最近更新 更多