zacwest / ZSWTappableLabel

UILabel subclass for links which are tappable, long-pressable, 3D Touchable, and VoiceOverable.
MIT License
169 stars 37 forks source link

Swift 4/XCode 9 #27

Closed crspybits closed 7 years ago

crspybits commented 7 years ago

I think this example:

let string = NSLocalizedString("Privacy Policy", comment: "")
let attributes: [String: Any] = [
  ZSWTappableLabelTappableRegionAttributeName: true,
  ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.lightGray,
  ZSWTappableLabelHighlightedForegroundAttributeName: UIColor.white,
  NSForegroundColorAttributeName: UIColor.blue,
  NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue,
  SimpleSwiftViewController.URLAttributeName: URL(string: "http://imgur.com/gallery/VgXCk")!
]

label.attributedText = NSAttributedString(string: string, attributes: attributes)

doesn't work any more with NSAttributedStringKey keys for attributed strings.

crspybits commented 7 years ago

Here's what I have working:

        let agreementAttr:[NSAttributedStringKey : Any] = [
            NSAttributedStringKey(rawValue:ZSWTappableLabelTappableRegionAttributeName): true,
            NSAttributedStringKey.foregroundColor: UIColor.blue,
            NSAttributedStringKey(rawValue:ZSWTappableLabelHighlightedForegroundAttributeName): UIColor.lightGray,
            NSAttributedStringKey(rawValue: linkNameKey): userAgreementKey,
        ]
        let agreement = NSAttributedString(string: "User Agreement ", attributes: agreementAttr)
zacwest commented 7 years ago

I'll be updating this for Swift 4 (since I absolutely need it at work) in the next couple weeks, but I think it's just a few header changes, so PRs welcome!