2

コレクション ビューにヘッダー ビューを実装しました。3 つの項目を持つ 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];

セグメント化されたコントロールは次のようになります。

UISegmentedControl

セグメントを選択していない場合、セグメントのテキストがぼやけるのはなぜですか?

編集

解決しました![UIColor clearColor], UITextAttributeTextShadowColorに追加normalAttributes

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 に答える