这是我在模拟器上看到的内容:
这是我在设备上看到的内容:
这是代码:
- (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;
}
我有
答案 0 :(得分:1)
当我使用UIAppearance来设置该类型的所有控件时,我遇到了类似的问题。它与我试图从文本中删除阴影时有关,它会导致文本不显示。在允许阴影之后,您无法注意到它确实存在,并且文本重新出现。
我已向苹果提交了有关此问题的错误。
答案 1 :(得分:0)
试试这个:
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];