2

我在集合视图中实现了标题视图。它是一个包含三个项目的 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 现在看起来像这样:

UISegmentedControl

为什么未选中时段的文本模糊?

编辑

解决了!添加[UIColor clearColor], UITextAttributeTextShadowColornormalAttributes

4

2 回答 2

3

这很可能是由默认的 shadowColor 引起的。

尝试在您的titleTextAttributes中设置UITextAttributeTextShadowColor和。UITextAttributeTextShadowOffset

您可能需要进行试验以获得最佳视觉外观。您也可以简单地将 shadowColor 属性设置为[UIColor clearColor].

于 2013-07-11T09:39:22.163 回答
0

您也可能正在设置像素边界之间的帧。使用CGRectIntegral对我有用。

于 2014-06-19T14:50:28.763 回答