UISegmentedControlのセグメントの色とフォントサイズを変更したいと考えています。私は、各セグメントのタグを設定して、各セグメントのtintColor:forTag:を設定しています。UISegmentedControl - 色とサイズの変更 - 正常に動作しない
色を変更すると、コントロールをパンするかピンチするまでうまくいきます。 UIPinchGestureRecognizerコードでは、titleTextAttributesを異なるフォントサイズに設定しました。これを行うと、セグメントの色はデフォルトのGary Colorに戻ります。
- (void)createElement {
if (multiStateControl == nil) {
//Make our new switch
//multiStateControl = [UIButton buttonWithType:UIButtonTypeCustom];
multiStateControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Off State Button", @"On State Button", nil]];
multiStateControl.segmentedControlStyle = UISegmentedControlStyleBar;
[multiStateControl setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12.0f], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
[multiStateControl setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 30.0f)];
// Set up the Contents Frame to the same origin as what we were but set the height/width to the new control.
[elementViewContents setFrame:CGRectMake(elementViewContents.frame.origin.x,
elementViewContents.frame.origin.y,
CGRectGetWidth(multiStateControl.frame),
CGRectGetHeight(multiStateControl.frame))];
//Set initial use to disabled
[multiStateControl setOpaque:NO];
// Set the default title for the button
[multiStateControl setTag:kTagOffState forSegmentAtIndex:0];
[multiStateControl setTag:kTagOnState forSegmentAtIndex:1];
[multiStateControl setTintColor:onColor forTag:kTagOnState];
[multiStateControl setTintColor:offColor forTag:kTagOffState];
// Lets get it on the screen
[elementViewContents addSubview:multiStateControl];
[multiStateControl release];
[self contentSizeChanged];
}
}
//ピンチジェスチャー
-(void) pinchElement:(UIPinchGestureRecognizer *)gestureRecognizer {
UIFont *existingFont = [[multiStateControl titleTextAttributesForState:UIControlStateNormal] objectForKey:UITextAttributeFont];
CGFloat existingFontSize = [existingFont pointSize];
CGFloat newFontSize = existingFontSize * [gestureRecognizer scale] ;
[multiStateControl setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:newFontSize],
UITextAttributeFont, nil]
forState:UIControlStateNormal];
[multiStateControl setFrame:CGRectMake(multiStateControl.frame.origin.x, multiStateControl.frame.origin.y, multiStateControl.frame.size.width+20,newFontSize *1.8)];
}
TextColorには意味があります。私はそれを確認していないよ、私は、ありがとう、ありがとう。私が問題を抱えている色は、セグメントの色合いです。セグメントのTintColorセグメントがTextAttributes内に隠されていますか? – scooter133
tintが属性にないように見える場合は、tintColor:メソッドを使用してフォントを設定し、setTintColorを使用する必要があります: – valexa