2013-09-23 11 views
7

मैं जानना चाहता हूं कि UIButton के शीर्षक रंग को डिफ़ॉल्ट मान पर कैसे बदला जाए।UIButton डिफ़ॉल्ट शीर्षक रंग आईओएस 7

मेरे पास एक बटन है जिसे मैं शीर्षक रंग बदलता हूं ताकि इस पर कुछ संकेत हो सके;

[cell.offStateSwitch setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

फिर जब यह बंद है, मैं इसे वापस डिफ़ॉल्ट रंग को बदलना चाहते हैं।

मैं यह नहीं समझ सकता कि UIButton के लिए डिफ़ॉल्ट सिस्टम रंग कैसे प्राप्त करें। मैंने पाया है कि बहुत से लोग एक विशेष आरजीबी मूल्य को मजबूर कर ऐसा कर रहे हैं, लेकिन यह आईओएस के विभिन्न संस्करणों में जरूरी नहीं है।

उत्तर

1

आईओएस में डिफ़ॉल्ट शीर्षक रंग के लिए कोई संपत्ति नहीं है, आप इसे आसानी से प्राप्त कर सकते हैं।

बस defaultColor को परिभाषित:

UIColor* defaultColor; फिर अपने viewDidLoad पुट में या जहां दृश्य प्रारंभ हो:

defaultColor = [button titleColorForState: UIControlStateNormal]; 

तो फिर तुम defaultColor है डिफ़ॉल्ट शीर्षक रंग के रूप में।

0

फिर बटन कार्रवाई में

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

cell.button.tag=indexPath.row+100; 

[cell.button addTarget:self selector:@selector(changeButtonTitle:) forControlEvents:UIcontrolTouchUpEventInside]; 

cellForRowAtIndexPath प्रतिनिधि में निम्न कोड जोड़ें ...... निम्नलिखित कोड

-(void)changeButtonTitle:(UIButton *)button 
{ 
    UITableViewCell *cell=(UITableViewCell *)button.superview.superview; 
    NSIndexpath *indexpath=[self.yourtableview indexPathForCell:cell]; 
    UIButton *tempButton=(UIButton *)[cell viewWithtag:indexPath.row+100]; 
    [tempButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 
} 
9

मुझे लगता है तुम्हारा मतलब आप पाठ वापस सेट करना चाहते हैं जोड़ने tintColor पर। तुम सिर्फ वर्तमान tintColor चाहते हैं, आप कर सकते हैं:

[button setTitleColor:button.tintColor forState:UIControlStateNormal]; 

हालांकि, tintColor स्वचालित रूप से इस तरह के एक चेतावनी पॉप अप होता है जब के रूप में कुछ निश्चित परिस्थितियों में परिवर्तित करने के लिए माना जाता है। आदेश है कि प्राप्त करने के लिए, मैं आप अपने खुद के बटन परिभाषित करने की जरूरत लगता है: उस मामले में

@interface MyButton : UIButton 
@end 

@implementation MyButton 

- (void) tintColorDidChange 
{ 
    [self setTitleColor:self.tintColor forState:UIControlStateNormal]; 
    [super tintColorDidChange]; 
} 

@end 

, मैं तुम्हें विशेष रंग आपके लिए चयनित राज्य का उपयोग का प्रस्ताव:

[button setTitleColor:[UIColor redColor] forState:UIControlStateSelected]; 

और button.selected = YES जब सेट जैसा कि आप कहते हैं, "कुछ चालू है"।

11

रंग को शून्य पर सेट करें और इसका व्यवहार वापस लौटने से पहले यह बदल जाएगा कि अलर्ट के लिए सही तरीके से जवाब देना शामिल है।

[myButton setTitleColor:nil forState:UIControlStateNormal]; 
5
button.tintColor = nil 

या

[button setTintColor: null] 

आईओएस v7.0 में, UIView के सभी उपवर्गों आधार वर्ग से tintColor के लिए उनके व्यवहार निकाले जाते हैं। अधिक जानकारी के लिए UIView स्तर पर tintColor की चर्चा देखें।

इस संपत्ति का UIButtonTypeCustom टाइप करने वाले बटनों के लिए कोई डिफ़ॉल्ट प्रभाव नहीं है। कस्टम बटन के लिए, आपको टिनकॉलर से संबंधित किसी भी व्यवहार को लागू करना होगा।

शून्य (शून्य) को UIButton के tintColor की स्थापना अपने शीर्षक का रंग रीसेट कर देगा

संबंधित मुद्दे