2011-12-08 4 views
9

可能性の重複は:
UISegmentedControl selected segment color
UISegmentcontrol appearances causing issuesUISegmentcontrolフォントと選択したセグメントの色を変更するには?

こんにちは私は、カスタムフォントにデフォルトUISegmentControlのフォントを変更し、暗いのではなく、別の色に、選択したセグメントの色を変更するようになります色。

おかげでこの

enter image description here

編集するには、この

enter image description here

から

:と呼ばれるソリューション

//フォントサイズの変更、影を削除し、選択したテキスト&背景色が通常の状態と異なっている

-(void)defineSegmentControlStyle 
    { 
     //normal segment 
     NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
            [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont, 
            [UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor, 
            [UIColor clearColor], UITextAttributeTextShadowColor, 
            [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
            nil];//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor]; 
     [infoSegment setTitleTextAttributes:normalAttributes forState:UIControlStateNormal]; 

     NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
              [UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont, 
              [UIColor whiteColor], UITextAttributeTextColor, 
              [UIColor clearColor], UITextAttributeTextShadowColor, 
              [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
              nil] ;//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor]; 
     [infoSegment setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected]; 

    } 
+0

http://stackoverflow.com/a/5932524/102937 –

答えて

1

あなたがチェックアウトすることがあり、この: http://idevrecipes.com/2010/12/11/custom-segmented-controls/

+0

返信いただきありがとうございますが、私もカスタムフォントを設定する必要があることを知りました... – Desmond

+0

多分これでしょうか? http://www.iphonedevsdk.com/forum/iphone-sdk-development/5059-change-font-size-text-uisegmentedcontrol.html –

+0

UISegmentedControlで、選択していないセグメントとは異なるセグメントのフォントサイズを変更することはできますか?選択したセグメントの色は変更できますが、フォントサイズは変更できません。 – Shreyas

関連する問題