ios - Clicking on NSURL in a UITextView -


i have uitextview spans 100.0 points across uiview.

in uitextview, have links captured following function:

- (bool) textview:(uitextview *)textview shouldinteractwithurl:(nsurl *)url inrange:(nsrange)characterrange 

this works great capture characters have 1 problem: if link last characters in text view, tap pressed way across line.

so if have text view following text @test link:

// entire remainder of line link (all white space after @test) hello @test 

how fix this?

for me highlights link... missing something?

enter image description here

update:

here's hacky solution via dummy url's:

- (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];     nsmutableattributedstring* attributedstring = [[nsmutableattributedstring alloc] init];     [attributedstring appendattributedstring:[[nsattributedstring alloc] initwithstring:@"lorem ipsum dolor sit amet, vim iuvaret blandit intellegebat ut. solet diceret interpretaris eos cu, magna dicat explicari mei ex, cibo adversarium eu pro. ei odio saepe eloquentiam cum, nisl case nec ut. harum habemus definiebas et vix, est cu aeque sonet, in salutatus repudiare deterruisset. quo duis autem intellegat an, regione propriae et vis."]];      nsattributedstring* dummyurl = [[nsattributedstring alloc] initwithstring:@" " attributes:@{ nslinkattributename : @"http://dummy.com" }];     nsattributedstring* url = [[nsattributedstring alloc] initwithstring:@"http://stackoverflow.com" attributes:@{ nslinkattributename : @"http://stackoverflow.com" }];     [attributedstring appendattributedstring:dummyurl];     [attributedstring appendattributedstring:url];     [attributedstring appendattributedstring:dummyurl];     self.textview.attributedtext = attributedstring; }  - (bool)textview:(uitextview *)textview shouldinteractwithurl:(nsurl *)url inrange:(nsrange)characterrange {     return ![url.absolutestring isequaltostring:@"http://dummy.com"]; } 

basically force uitextview recognise tap before , after stackoverflow link dummy link. since it's space it's invisible, unfortunately if tap , hold before/after stackoverflow link you'll see space highlighted gray, despite shouldinteractwithurl returning no. unfortunately seems cannot circumvent behaviour unless implement own uitextfield scratch...


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -