我在集合视图中实现了标题视图。它是一个包含三个项目的 UISegmentedControll。
这是代码:
NSArray *itemArray = [NSArray arrayWithObjects: @"Following", @"Everybody", @"Nearby", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
UIFont *font = [UIFont fontWithName:@"PatuaOne-Regular" size:12.0f];
UIColor *notChosenButtonColor = [UIColor colorWithRed:(201.0/255.0f) green:(198.0/255.0f) blue:(191.0/255.0f) alpha:1.0];
UIColor *chosenButtonColor = [UIColor colorWithRed:(235.0/255.0f) green:(218.0/255.0f) blue:(102.0/255.0f) alpha:1.0];
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
font, UITextAttributeFont,
notChosenButtonColor, UITextAttributeTextColor,
nil];
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
font, UITextAttributeFont,
chosenButtonColor, UITextAttributeTextColor,
nil];
[segmentedControl setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
[segmentedControl setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
[segmentedControl setBackgroundImage:[UIImage imageNamed:@"greenbt_bg.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentedControl setBackgroundImage:[UIImage imageNamed:@"standard_bt_h"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[segmentedControl setBackgroundColor:[UIColor clearColor] ];
segmentedControl.frame = CGRectMake(5, 20, 280, 25);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 0;
[segmentedControl setDividerImage:[UIImage imageNamed:@"separator.png"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[headerView addSubview:segmentedControl];
segmentedcontrol 现在看起来像这样:
为什么未选中时段的文本模糊?
编辑
解决了!添加[UIColor clearColor], UITextAttributeTextShadowColor
到normalAttributes