2010-06-11 11 views
8

इस UIButton के बारे में सब कुछ उस पाठ को छोड़कर महान प्रस्तुत करता है जो उस पर होना चाहिए। एनएसएलओजी दर्शाता है कि पाठ सही जगह पर है। क्या देता है?यह UIButton क्यों अपना टेक्स्ट लेबल नहीं दिखाता है?

UIButton *newTagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[newTagButton addTarget:self action:@selector(showNewTagField) forControlEvents:UIControlEventTouchUpInside]; 
newTagButton.titleLabel.text = @"+ New Tag"; 
NSLog(@"Just set button label to %@", newTagButton.titleLabel.text); 
newTagButton.titleLabel.font = [UIFont systemFontOfSize:17]; 
newTagButton.titleLabel.textColor = [UIColor redColor]; 
CGSize addtextsize = [newTagButton.titleLabel.text sizeWithFont:[UIFont systemFontOfSize:17]]; 
CGSize buttonsize = { (addtextsize.width + 20), (addtextsize.height * 1.2) }; 
newTagButton.frame = CGRectMake(x, y, buttonsize.width, buttonsize.height); 
[self.mainView addSubview:newTagButton]; 

उत्तर

20

UIButton पर एपीआई का एक सेट है जिसका उपयोग उन गुणों को बदलने के लिए किया जाना चाहिए।

शीर्षक लेबल लेबल और आंतरिक रूप से UIButton द्वारा बदला जाएगा।

[button setTitle:title forState:state]; 
[button setTitleColor:color forState:state]; 
[button setTitleShadowColor:color forState:state]; 

तुम हमेशा इन तरीकों (उपलब्ध होने पर) नहीं बल्कि सीधे titleLabel छू से के माध्यम से इन गुणों को सेट करना चाहिए। फोंट के लिए आप इसे शीर्षक लेबल पर सीधे बदल सकते हैं क्योंकि वे UIButton पर कोई विधि प्रदान नहीं करते हैं।

+0

बिंगो। धन्यवाद! –

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