【问题标题】:Segmented Control title shows on simulator but not device分段控制标题显示在模拟器上,但不显示在设备上
【发布时间】:2013-08-25 17:06:39
【问题描述】:

这是我在模拟器上看到的:

这是我在设备上看到的:

这是代码:

- (void)buildNavBarTitle
{
    self.navigationItem.title = nil;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, self.navigationController.navigationBar.frame.size.height)];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 160, view.frame.size.height - 10)];
    segmentedControl.tintColor = [UIColor blackColor];
    [segmentedControl insertSegmentWithTitle:@"New" atIndex:0 animated:NO];
    [segmentedControl insertSegmentWithTitle:@"Today" atIndex:1 animated:NO];

    [view addSubview:segmentedControl];
    self.navigationItem.titleView = view;
}

我有

  • 已删除模拟器和设备上的应用
  • 重新启动 xCode
  • cmd+shift+k 清理
  • cmd+shift+alt+k 擦除构建文件夹

【问题讨论】:

  • 你的模拟器和设备是完全相同的ios吗?
  • 都是6.1,但是模拟器是“6.1 (10B141)”,设备是“6.1.3 (10B329)”
  • 使用 UISegmentedControl initWithItems: 初始化程序有什么不同吗?初始化后不要忘记设置框架。

标签: ios


【解决方案1】:

当我使用 UIAppearance 为该类型的所有控件设置样式时,我遇到了类似的问题。这与我试图从文本中删除阴影有关,它导致文本不出现。允许阴影后,你并没有注意到它真的在那里,文字又出现了。

我已就此向苹果提交了一个错误。

【讨论】:

    【解决方案2】:

    试试这个:

    NSArray *itemArray = [NSArray arrayWithObjects: @"New", @"Today", nil];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]
    segmentedControl.frame = CGRectMake(35, 200, 250, 50);
    segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
    segmentedControl.selectedSegmentIndex = 0;
    [view addSubview:segmentedControl];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      相关资源
      最近更新 更多