Link

This component enables links to other resources, pages or views.

Backpack/TappableLinkLabel

Cocoapods class reference view on Github

Day Night

Alternate style

Day Night

Usage

BPKTappableLinkLabel is a view that renders flowing text that can include tappable links as part of its content.

Objective-C


                                                
                                                #import <Backpack/TappableLinkLabel.h>
                                                
                                                BPKTappableLinkLabel *tappableLinkLabel = [[BPKTappableLinkLabel alloc] initWithFontStyle:BPKFontStyleTextBase];
                                                tappableLinkLabel.text = @“Find out more about our terms of service.”
                                                tappableLinkLabel.delegate = self;
                                                
                                                [tappableLinkLabel addLinkToURL:[NSURL URLWithString:@"http:..."] withRange:NSRange(location:24, length:16)];
                                                [tappableLinkLabel addLinkToTransitInformation:@{} withRange:NSRange(location:24, length:16)];
                                                // Position label with autolayout or other method
                                                
                                                // Apply alternative style:
                                                tappableLinkLabel.style = BPKTappableLinkLabelStyleAlternative;
                                                
                                                // Apply custom text color:
                                                tappableLinkLabel.textColor = BPKColor.panjin;
                                                
                                                ...
                                                
                                                #pragma mark - <BPKTappableLinkLabelDelegate>
                                                
                                                - (void)tappableLabel:(BPKTappableLinkLabel *)label didSelectLinkWithURL:(NSURL *)url {
                                                    [_presenter urlTapped:url];
                                                }
                                                
                                                - (void)tappableLabel:(BPKTappableLinkLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components {
                                                    // do stuff
                                                }

Swift


                                                
                                                import Backpack
                                                
                                                let tappableLinkLabel = BPKTappableLinkLabel(fontStyle: .textBase)
                                                tappableLinkLabel.text = “Find out more about our terms of service.”
                                                tappableLinkLabel.delegate = self
                                                
                                                tappableLinkLabel.addLink(to: URL(string: "https:...")!, withRange: Range(location:24, length:16))
                                                tappableLinkLabel.addLink(toTransitInformation: ["identifier": "some link thing"], withRange: Range(location:24, length:16))
                                                // Position label with autolayout or other method
                                                
                                                // Apply alternative style:
                                                tappableLinkLabel.style = .alternative
                                                
                                                // Apply custom text color:
                                                tappableLinkLabel.textColor = BPKColor.panjin
                                                
                                                ...
                                                
                                                extension MyClass: BPKTappableLinkLabelDelegate {
                                                  func tappableLabel(_ label: BPKTappableLinkLabel, didSelectLinkWith url: URL) {
                                                      UIApplication.shared.open(url, options: [:], completionHandler: nil)
                                                  }
                                                
                                                  func tappableLabel(_ label: BPKTappableLinkLabel,
                                                                       didSelectLinkWithTransitInformation components: [AnyHashable: Any]) {
                                                      print(components)
                                                  }
                                                }

Appearance attributes

  • (UIColor)linkContentColor