What is the best working approach for having a substring as hyperlink?

189 Views Asked by At

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.

0

There are 0 best solutions below