2017-02-21 5 views
0

shouldInteractWith url textviewデリゲートはios9では呼び出されませんが、ios9デ​​リゲートメソッドも実装されています。コードは以下のとおりです。誰かが問題を修正していることを知っている場合は、私に知らせてください。任意のヘルプshouldInteractWith url textviewデリゲートはios9では呼び出されませんが、ios10では機能しますか?

import UIKit 

class UrNestTermsView: UIView { 

// Outlets 
@IBOutlet weak var contentView: UIView! 
@IBOutlet weak var termsTextView: UITextView! 
@IBOutlet weak var termsUrNestCheckBox: UrNestCheckBox! 
@IBOutlet weak var subscribeUrNestCheckBox: UrNestCheckBox! 
@IBOutlet weak var subscribeTextView: UITextView! 

fileprivate let fontOfTerms = UIFont.systemFont(with: 10) 
fileprivate let labelTextColor = UIColor(colorLiteralRed: 102/255, green: 110/255, blue: 111/255, alpha: 1) 

override func awakeFromNib() { 
    super.awakeFromNib() 
    self.setUp() 
} 
} 

extension UrNestTermsView: UITextViewDelegate { 

func setUp() { 
    self.subscribeTextView.textColor = labelTextColor 
    self.subscribeTextView.font = fontOfTerms 
    self.setUpTextView() 
} 

func setUpTextView() { 

    // You must set the formatting of the link manually 
    let linkAttributeTermsOfService = [ 
     NSLinkAttributeName: NSURL(string: "https://www.apple.com")!, 
     NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, 
     NSForegroundColorAttributeName: labelTextColor 
     ] as [String : Any] 
    let linkAttributePolicy = [ 
     NSLinkAttributeName: NSURL(string: "https://www.google.com")!, 
     NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, 
     NSForegroundColorAttributeName: labelTextColor 
     ] as [String : Any] 
    let linkAttributePaymentsTermsOfService = [ 
     NSLinkAttributeName: NSURL(string: "https://www.amazon.com")!, 
     NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, 
     NSForegroundColorAttributeName: labelTextColor 
     ] as [String : Any] 
    let linkAttributeGuestRefundPolicy = [ 
     NSLinkAttributeName: NSURL(string: "https://www.yahoo.com")!, 
     NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, 
     NSForegroundColorAttributeName: labelTextColor 
     ] as [String : Any] 
    let linkAttributeHostGuaranteeTerms = [ 
     NSLinkAttributeName: NSURL(string: "https://www.assembla.com")!, 
     NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, 
     NSForegroundColorAttributeName: labelTextColor 
     ] as [String : Any] 


    let attributedString = NSMutableAttributedString(string: kTermsAndPolicy) 

    // Set the 'click here' substring to be the link 
    attributedString.setAttributes(linkAttributeTermsOfService, range: NSMakeRange(33, 16)) 
    attributedString.setAttributes(linkAttributePolicy, range: NSMakeRange(51, 6)) 
    attributedString.setAttributes(linkAttributePaymentsTermsOfService, range: NSMakeRange(59, 25)) 
    attributedString.setAttributes(linkAttributeGuestRefundPolicy, range: NSMakeRange(102, 19)) 
    attributedString.setAttributes(linkAttributeHostGuaranteeTerms, range: NSMakeRange(127, 20)) 


    attributedString.addAttribute(NSFontAttributeName, value: fontOfTerms, range: NSMakeRange(0, attributedString.length-1)) 
    attributedString.addAttribute(NSForegroundColorAttributeName, value: labelTextColor, range: NSMakeRange(0, attributedString.length-1)) 

    self.termsTextView.delegate = self 
    self.termsTextView.attributedText = attributedString 

    let attributedStringOfSubscribe = NSMutableAttributedString(string: kSubscribe) 
    attributedStringOfSubscribe.addAttribute(NSFontAttributeName, value: fontOfTerms, range: NSMakeRange(0, attributedStringOfSubscribe.length)) 
    attributedStringOfSubscribe.addAttribute(NSForegroundColorAttributeName, value: labelTextColor, range: NSMakeRange(0, attributedStringOfSubscribe.length)) 

    self.subscribeTextView.delegate = self 
    self.subscribeTextView.attributedText = attributedStringOfSubscribe 
} 

//For iOS 7...9 
@available(iOS, deprecated: 10.0) 
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool { 
    return true 
} 

@available(iOS 10.0, *) 
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { 
    return true 
} 

} 
+0

こんにちは、あなたは解決策を見つけ出すのですか? – HungCLo

+0

こんにちは、まだ私は解決策を見つけません – Sakthimuthiah

答えて

2

ための事前のおかげで、これを試してみてください。

@available(iOS, deprecated: 10.0) 
func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange) -> Bool { 
    return true 
} 

//For iOS 10 
@available(iOS 10.0, *) 
func textView(_ textView: UITextView, shouldInteractWith url: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool { 
    return true 
} 
+0

助けてくれてありがとう、私は試したが、ios9のために働いていない – Sakthimuthiah

関連する問題