1

I am using TSLabel. It is working really good for iOS 10.2 and lower versions but does'nt work in iOS 10.3. I also tried to use TTTAttribuedLabel but because of some reason the framework crashes in its one of the method. Right now i am stuck. I dont know what exactly i should use. In TSLabel there is a method as

- (void) layoutManager: (NSLayoutManager *) layoutManager didCompleteLayoutForTextContainer: (NSTextContainer *) textContainer atEnd: (BOOL)layoutFinishedFlag {
// search for our custom label attribute - if we have it we'll tell it about link bounds!
TSLabel* label = [[self attribute: TSLabelAttributeName
                         atIndex: 0
                  effectiveRange: nil] object];

if ( label != nil && [label isKindOfClass: [TSLabel class]] )
{
    CGRect containerGlyphBounds = [layoutManager boundingRectForGlyphRange: [layoutManager glyphRangeForTextContainer: textContainer] inTextContainer: textContainer];

    // determine the bounds of each link and record that information with the TSLabel
    NSMutableSet* links = [NSMutableSet new];
    [self enumerateAttribute: TSLinkAttributeName
                     inRange: NSMakeRange(0, self.length)
                     options: 0
                  usingBlock: ^(NSURL* url, NSRange range, BOOL *stop) {

                      if ( url != nil )
                      {
                          TSLinkInfo* link = [TSLinkInfo new];
                          link.url = url;
                          link.range = range;

                          NSRange glyphRange = [layoutManager glyphRangeForCharacterRange: range actualCharacterRange: nil];
                          CGRect bounds = [layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: textContainer];
                          link.bounds = CGRectOffset(bounds, 0, (label.bounds.size.height-containerGlyphBounds.size.height)/2);

                          [links addObject: link];
                      }
                  }];

    label.links = links;
}
}

Which doesn't get called only in iOS 10.3 and In case of TTTAtributedLabel The framework works fine if i create new project and put the same code which is in my project. This TTTAttributedLabel only crashes in my project. It crashes in below method:

- (NSArray *) links {
return [_linkModels valueForKey:@"result"];
}

The LinkModels becomes NSZombie.

Uzair Dhada
  • 333
  • 2
  • 6
  • 23
  • There are some bugs with `NSAttributedString` in iOS 10.3, maybe that's what causing your problem. What's the crash, could you share that and the code? – koen Apr 24 '17 at 20:15
  • You can use `NSDataDetector` to get the ranges of your links in your string. Then you can use those ranges to underline the links. Use a `UITapGestureRecognizer` to detect the tap, and if it is in the range of a link, you can do your next step. – koen Apr 24 '17 at 20:18
  • @Koen For your first comment, Are you asking for the `TSLabel` Library or `TTTAttributedLabel`? I want to do something like this Hello Please Click Here. So Here will be having a link, There is chance of having Phone number also there. If i use `UITapGestureRecognizer` then will i be having that tint feel? Like we have on `UIButton`? – Uzair Dhada Apr 25 '17 at 05:22
  • I don't use those libraries, just the `attributedString` property of a `UILabel`. – koen Apr 25 '17 at 10:41
  • Can you help me out with this? I mean how i can directly do with `attributedString`? – Uzair Dhada Apr 25 '17 at 10:43
  • To get started, see my comments above about `NSDataDetector` and `UITapGestureRecognizer`. If you get stuck, please post a new question with a specific problem. – koen Apr 25 '17 at 11:26
  • Please add more details about the crash and what doesn't work in 10.3 to this question (see also: https://stackoverflow.com/help/how-to-ask). – koen Apr 25 '17 at 11:28
  • @Koen I have updated the question. – Uzair Dhada Apr 25 '17 at 11:50
  • You need to do some basic debugging, step through the code and try to find out why it works on iOS 10.2 but not on iOS 10.3. And maybe file a bug on the TSLabel GitHub page. – koen Apr 25 '17 at 14:19
  • @Koen Thanks Ill surely do that. – Uzair Dhada Apr 26 '17 at 09:14

0 Answers0