2014-10-22 6 views
8

के साथ काम नहीं कर रहा है I UTableViewCell के लेबल में टेक्स्ट के लिंक का पता लगाने के लिए TTTAttributedLabel का उपयोग करना चाहता हूं, लेकिन यह काम नहीं करता है। मैं आईओएस 8 के साथ तेजी से उपयोग कर रहा हूँ।TTTAttributedLabel लिंक IIS8 में तेजी से

class StoryTableViewCell: UITableViewCell, TTTAttributedLabelDelegate { 
    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 

     // Link properties 
     let textLabel = self.descriptionLabel 
     let linkColor = UIColor(red: 0.203, green: 0.329, blue: 0.835, alpha: 1) 
     let linkActiveColor = UIColor.blackColor() 

     if (textLabel is TTTAttributedLabel) { 
      var label = textLabel as TTTAttributedLabel 
      label.linkAttributes = [NSForegroundColorAttributeName : linkColor] 
      label.activeLinkAttributes = [NSForegroundColorAttributeName : linkActiveColor]   
      label.enabledTextCheckingTypes = NSTextCheckingType.Link.toRaw() 

      label.delegate = self 
     } 
    } 
} 
+0

जांचें: http://stackoverflow.com/a/22395136/1106035 –

+0

@ प्रिंस यह काम नहीं कर रहा है – JeremyWei

उत्तर

12

मुझे लगता है कि आप अपने custom cellसही ढंग से कॉन्फ़िगर नहीं किया है: नीचे UITableViewCell कोड है।

आपके कस्टमसेल में पहले घोषित करें और अपने IBOutlet -s को कनेक्ट करें। अपना टेक्स्ट लेबल चुनें और अपनी कक्षा TTTAttributedLabel पर जोड़ें। आपका कस्टम सेल इस तरह दिखना चाहिए:

class StoryTableViewCell: UITableViewCell { 
    @IBOutlet weak var textLabel: TTTAttributedLabel! 

    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 

     // Configure the view for the selected state 
    } 
} 

दूसरा आप कक्षा में TTTAttributedLabelDelegate जोड़ने के लिए जहां tableView डेटा स्रोत और प्रतिनिधि का उपयोग कर रहे जरूरत है।

फिर तहत cellForRowAtIndexPath

var cell: StoryTableViewCell = tableView.dequeueReusableCellWithIdentifier("yourCellIdentifier") as StoryTableViewCell 

let linkColor = UIColor(red: 0.203, green: 0.329, blue: 0.835, alpha: 1) 
let linkActiveColor = UIColor.blackColor() 

cell.textLabel.delegate = self 

cell.textLabel.linkAttributes = [kCTForegroundColorAttributeName : linkColor] 
cell.textLabel.activeLinkAttributes = [kCTForegroundColorAttributeName : linkActiveColor]   
cell.textLabel.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue 

तो अगर आप तरीकों TTTAttributedLabelDelegate से निष्पादित करने के लिए उन्हें जोड़ने के लिए और अपनी गणना करने की आवश्यकता है।

यह मदद करता है

+0

मैंने आपके उत्तर का पालन किया लेकिन मैं इसे काम करने में सक्षम नहीं हूं। इसे डीबग करने के बारे में कोई विचार? पाठ वहां है लेकिन कोई लिंक नहीं मिला है। – rsc

+0

अद्यतन 1: मैंने प्रतिनिधियों के कार्यों को जोड़कर डीबगिंग शुरू की है लेबल ने किया है चयन करें LinkWithURL और didLongPressLinkWithURL। पूर्व काम नहीं कर रहा था लेकिन बाद वाला है। अद्यतन 2: didSelectLinkWithURL को नहीं कहा जा रहा था क्योंकि मेरे पास tapper.cancelsTouchesInView = true के साथ एक दृश्य था। जब मैंने इसे गलत पर सेट किया, तो क्लिक करने के लिए क्लिक करना शुरू हो गया। – rsc

+5

ऐसा प्रतीत होता है कि NSForegroundColorAttributeName आईओएस 8 पर काम नहीं कर रहा है। यदि ऐसा होता है, तो इसके बजाय केवल kCTForegroundColorAttributeName का उपयोग करें। – rsc

0
let linkColor = UIColor.blueColor() 
    let linkActiveColor = UIColor.greenColor() 

    textLabel.delegate = self 

    textLabel.linkAttributes = [kCTForegroundColorAttributeName : linkColor.CGColor,kCTUnderlineStyleAttributeName : NSNumber(bool: true)] 
    textLabel.activeLinkAttributes = [NSForegroundColorAttributeName : linkActiveColor] 
    textLabel.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue 
+0

हाय कामलेश मुझे tttattributedlabel में छंटनी टोकन में समस्या पर क्लिक करने का सामना करना पड़ रहा है। क्या आपको इसका कोई विचार है? – Aditya

3

आप अपने UILabel की श्रेणी के रूप TTTAttributedLabel चुके हैं, तो एक निब या स्टोरीबोर्ड भीतर आशा है, सुनिश्चित करें कि उपयोगकर्ता सहभागिता सक्षम सही पर सेट किया जाता है, के रूप में एक डिफ़ॉल्ट जा कर यूलाबेल में उपयोगकर्ता इंटरैक्शन अक्षम होगा।

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