The best scenario for a label that needs to support replication and hyperlink snooping is to use Uitextview instead of a label
Set up TextView support hyperlinks
TextView default Hyperlink Click is applied outside the jump to implement in-app jump, you need to follow the Uitextviewdelegate implementation Uitextviewdelegate Proxy method, intercept to hyperlink URL yourself in the app to do jump
-(BOOL) TextView: (Uitextview *) TextView Shouldinteractwithurl: (Nsurl *) URL InRange: (nsrange) CharacterRange { if ( [Self.delegate respondstoselector: @selector (clickurl:)]) { [self.delegate clickurl:[url.absolutestring stringbyreplacingpercentescapesusingencoding: Nsutf8stringencoding]]; } NSLog (@ "%@", url.absolutestring); return NO; }
-(BOOL) TextView: (Uitextview *) TextView Shouldinteractwithurl: (Nsurl *) URL InRange: (nsrange) CharacterRange return YES In addition to listening to tap events or listening to long press the event long press the pop-up copy Share button, but click Open will jump to the outside of the app opens the link, return no only listen to the linked click event does not listen to other events such as long press the pop-up Copy share button, so that we can customize Pop-up button, then do the copy and in-app open links and other actions
-(BOOL) TextView: (Uitextview *) TextView Shouldinteractwithurl: (Nsurl *) URL InRange: (nsrange) CharacterRange { if ( [Self.delegate respondstoselector: @selector (clickurl:)]) { [self.delegate clickurl:[url.absolutestring stringbyreplacingpercentescapesusingencoding: Nsutf8stringencoding]]; } return NO;}
Controller inside the implementation of the agent
-(void) Clickurl: (NSString *) URL {uialertcontrollerstyle style = Uialertcontrollerstyleactionsheet; if ([Phoneutil Ispaddevice]) {//fit ipad style = Uialertcontrollerstylealert; } Uialertcontroller *ALERTVC = [Uialertcontroller alertcontrollerwithtitle:url message:nil PreferredStyle:style]; Processing replication Uialertaction *copyaction = [uialertaction Actionwithtitle:getstringbykey (@ "string_key_616") style: Uialertactionstyledefault handler:^ (uialertaction * _nonnull action) {Uipasteboard *pasteboard = [UIPasteboard gen Eralpasteboard]; pasteboard.string = URL; }]; Handle link Click in App jump Uialertaction *openaction = [uialertaction Actionwithtitle:getstringbykey (@ "string_key_1370") style: Uialertactionstyledefault handler:^ (uialertaction * _nonnull action) {Uistoryboard *sb=[uistoryboard storyboardWit hname:@ "Setting" Bundle:[nsbundle Mainbundle]; WEBVIEWVC *vc=[sb instantiateviewcontrollerwithidentifier:@ "WEBVIEWVC"]; Vc.url = URL; [Self.navigationcontroller PUSHVIEWCONTROLLER:VC Animated:yes]; }]; Uialertaction *cancelaction = [uialertaction Actionwithtitle:getstringbykey (@ "string_key_219") style: Uialertactionstylecancel Handler:nil]; [ALERTVC addaction:copyaction]; [ALERTVC addaction:openaction]; [ALERTVC addaction:cancelaction]; [Self.navigationcontroller PRESENTVIEWCONTROLLER:ALERTVC Animated:yes completion:nil];}
IOS text free Copy Hyperlink listener