2013-08-27 5 views
8

काम नहीं करता है इसलिए मैंने अपने UISegmentedControl के शीर्षक की टेक्स्ट विशेषता को बदलने की कोशिश की, लेकिन यह काम नहीं करता है, कुछ भी नहीं बदलेगा। मैंने कस्टम पृष्ठभूमि और विभक्त भी लागू किया है और यह सही तरीके से काम करता है, लेकिन यह नहीं।UISegmentedControl setTitleTextAttributes

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]; 

उत्तर

11

आपने कुंजी और मूल्यों के गलत क्रम का उपयोग किया है, इसलिए यह काम नहीं कर रहा है।

प्रयास करें यह

[[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

काम करता है! तो इस विधि शब्दकोष शब्द पसंद नहीं है? – harinsa

+1

शब्दकोश शब्दकोष ठीक काम करते हैं; अगर वे नहीं करते, तो आईओएस में एक गंभीर बग होगा! '[स्वयं सेटटाइटटेक्स्ट एट्रिब्यूट्स: @ {यूआईटीएक्स्टएट्रिब्यूट टेक्स्टक्लोर: [यूआईसीओएलओआर रेडकोलर]} फॉरस्टेट: यूआईसींट्रोलस्टेट नॉर्मल];' – NathanAldenSr

+1

यह अच्छा होगा अगर उत्तर बताए कि कुछ काम करने के बजाए क्या गलत है। –

10

में अंतर से सावधान रहें आप कैसे कारखाने विधि के बीच अपने जोड़े (मूल्य/कुंजी)

[NSDictionary dictionaryWithObjectsAndKeys: value, key, nil] 

और शाब्दिक घोषणा आदेश (कुंजी/मूल्य)

@{key: value} 

आप बस कुंजी और मूल्य के गलत क्रम का उपयोग करते हैं।

यह काम करेगा:

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


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

इसे उत्तर स्वीकार किया जाना चाहिए – Renetik

6

ध्यान दें कि iOS 7 के बाद से इन कुंजियों में से कुछ अब पदावनत किया गया है। अब आपको कुछ उपयोग करने की आवश्यकता होगी:

[[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]; 
संबंधित मुद्दे