3

重複の可能性:
UISegmentedControlのフォントの色を変更する方法

selectedunselected segmentのテキストに異なるフォントの色を保持することは可能ですかUISegmentedControl。どんな助けでもありがたいです。

4

1 に答える 1

3
// Instantiate as usual
NSArray *items = [NSArray arrayWithObjects:@"first", @"second", [UIImage imageNamed:@"image.png"], nil];
MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];

// set frame, add to view, set target and action for value change as usual
segmentedControl.frame = CGRectMake(10.0f, 10.0f, 300.0f, 44.0f);
[self.view addSubview:segmentedControl];
[segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];

// Set a tint color
segmentedControl.tintColor = [UIColor orangeColor];

// Customize font and items color
segmentedControl.selectedItemColor = [UIColor yellowColor];
segmentedControl.unselectedItemColor = [UIColor darkGrayColor];

Interface Builderを使用する場合は、通常のUISegmentedControlを追加し、そのクラスをIdentity InspectorでMCSegmentedControlとして設定し、AttributesInspectorでTintを設定します。

現時点では、アニメーションと次のUISegmentedControlメソッドはサポートされていません。

- (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;
- (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment

ファイルは次のとおりです。

MCSegmentedControl.zip

于 2013-01-07T12:17:49.287 に答える