2013-08-27 14 views
8

Bu yüzden UISegmentedControl başlığımın metin özniteliğini değiştirmeyi denedim, ancak çalışmıyor, hiçbir şey değişmiyor. Ayrıca özel bir arka plan ve bölücü uyguladım ve doğru çalışıyor, ama bu değil.UISegmentedControl setTitleTextAttributes çalışmıyor

NSDictionary *normaltextAttr = 
      @{[UIColor blackColor]: UITextAttributeTextColor, 
       [UIColor clearColor]: UITextAttributeTextShadowColor, 
       [UIFont fontWithName:_regularFont size:20.f]: UITextAttributeFont}; 


NSDictionary *selectedtextAttr = 
      @{[UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0]: UITextAttributeTextColor, 
       [UIColor clearColor]: UITextAttributeTextShadowColor, 
       [NSValue valueWithUIOffset:UIOffsetMake(0, 1)]: UITextAttributeTextShadowOffset, 
       [UIFont fontWithName:_regularFont size:0.0]: UITextAttributeFont}; 

[[UISegmentedControl appearance] setTitleTextAttributes:normaltextAttr 
               forState:UIControlStateNormal]; 
[[UISegmentedControl appearance] setTitleTextAttributes:selectedtextAttr 
               forState:UIControlStateSelected]; 

cevap

11

Yanlış anahtar ve değer sırasını kullanmışsınız, bu nedenle çalışmıyor.

(fabrika yöntemine arasında çiftleri (değeri/anahtar)

[NSDictionary dictionaryWithObjectsAndKeys: value, key, nil] 

ve edebi deklarasyon sipariş nasıl Bu

[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor blackColor],UITextAttributeTextColor, 
                 [UIColor clearColor], UITextAttributeTextShadowColor, 
                 [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], UITextAttributeFont, nil] forState:UIControlStateNormal]; 

[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0],UITextAttributeTextColor, 
                 [UIColor clearColor], UITextAttributeTextShadowColor, 
                 [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
                 [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], UITextAttributeFont, nil] forState:UIControlStateSelected]; 
+0

işler! Yani bu yöntem sözlük literal sevmez? – harinsa

+1

Sözlük değişmezleri iyi çalışır; eğer yapmadılarsa, iOS'ta ciddi bir hata olur! '[self setTitleTextAttributes: @ {UITextAttributeTextColor: [UIColor redColor]} forState: UIControlStateNormal];' – NathanAldenSr

+1

Yanıtlar, çalışmakta olan bir şeyi yüklemek yerine sorunun ne olduğunu işaret ederse çok iyi olur. –

10

farkı dikkat anahtar deneyin/değeri10)

@{key: value} 

Sadece yanlış anahtar ve değer sırasını kullanın.

Bu çalışacaktır: iOS 7 beri bu tuşların bazıları şimdi artık yok edildiğini

NSDictionary *normaltextAttr = 
     @{UITextAttributeTextColor : [UIColor blackColor], 
     UITextAttributeTextShadowColor : [UIColor clearColor], 
     UITextAttributeFont : [UIFont fontWithName:_regularFont size:20.f]}; 


[[UISegmentedControl appearance] setTitleTextAttributes:normaltextAttr forState:UIControlStateNormal]; 
+0

Bu yanıt kabul edilmeli – Renetik

6

Not. Şimdi şu gibi bir şey kullanmanız gerekecek:

[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor blackColor], NSForegroundColorAttributeName, 
                 [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], NSFontAttributeName, nil] forState:UIControlStateNormal]; 

[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                 [UIColor colorWithRed: 135.0/255.0 green: 135.0/255.0 blue: 135.0/255.0 alpha: 1.0],NSForegroundColorAttributeName, 
                 [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], NSFontAttributeName, nil] forState:UIControlStateSelected]; 
İlgili konular