UILabel
सादे पाठ स्ट्रिंग्स (आईओएस 6 में यह अब भी NSAttributedString
रों प्रदर्शित कर सकते हैं, लेकिन यह पुराने iOS संस्करण में काम नहीं करेगा, तो यह इस पर निर्भर नहीं सबसे अच्छा है) प्रदर्शित करने में ही सक्षम है एक लेबल के साथ ऐसा करने में सक्षम नहीं होगा।
आप जिम्मेदार पाठ प्रदर्शित करने के लिए TTTAttributedLabel पर देख सकते हैं (इसलिए आप अंडरलाइन और अन्य स्वरूपण जोड़ सकते हैं), लेकिन आप इस कक्षा के साथ हाइपरलिंक जोड़ने में सक्षम नहीं होंगे।
विकल्प आप तार का एक क्लिक करने योग्य खंड के लिए है मूल रूप से कर रहे हैं:
उपयोग एक सादे UILabel
और भाग पर एक UIButton
कि आप क्लिक करने योग्य होना चाहते हैं, या
उपयोग ओवरले TTTAttributedLabel
अंडरलाइन प्रभाव प्राप्त करने के लिए, और UITapGestureRecognizer
टैप का पता लगाने और उन्हें संभालने के लिए (ध्यान दें कि यह पर पूरे लेबल पर नलियां कैप्चर करेगा, केवल रेखांकित भाग नहीं)।
iOS 6 के लिए:
UILabel *label = [[UILabel alloc] init];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Tap here to read the latest Football News."];
[string addAttribute:NSUnderlineStyleAttributeName value:@(1) range:NSMakeRange(4, 4)];
label.attributedText = [string copy];
पहले iOS संस्करण के साथ ही आईओएस 6 के लिए:
TTTAttributedLabel *label = [[TTTAttributedLabel alloc] init];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Tap here to read the latest Football News."];
[string addAttribute:NSUnderlineStyleAttributeName value:@(1) range:NSMakeRange(4, 4)];
label.text = [string copy];
फिर एक इशारा recogniser जोड़ सकते हैं और लागू handleTap:
:
UITapGestureRecognizer *recogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[label addGestureRecognizer:recogniser];
- (void)handleTap:(UITapGestureRecognizer *)recogniser {
// Handle the tap here
}
उसके लिए एक HTML स्ट्रिंग का उपयोग करें। और कस्टम लेबल में दिखाएं जो जिम्मेदार स्ट्रिंग का समर्थन करता है। – Divyu
मुझे एक उदाहरण दिखा सकता है ... – lakesh
आप http://stackoverflow.com/questions/7385892/how-can-i-set-substring-of-a-nsstring-as-bold-in-uilabel –