Touch Uitextview to find the text of the touch point

Source: Internet
Author: User

To participate in a game has a title, like the headline, in the Uitextview touch to find the corresponding text, the game can also check the information, when doing is to hold the mentality of playing to try and did not seriously do, did not check to eat, Came back from work last night thinking about this problem found that there is quite a level of this question is not simple, I tried to do the next, or in the stack overflow found in the answer. Http://stackoverflow.com/questions/19332283/detecting-taps-on-attributed-text-in-a-uitextview-in-ios

Oneself also tried, also quite good, originally thought that iOS basically do not have to learn, it seems to learn a lot of many, really rise posture.

Here is the demo record of my Test.

    _oxtextview=[[oxtouchtextview Alloc]initwithframe:cgrectmake (0)];    _oxtextview.text=@ "The Ape-ring is an Internet technology talent service platform, focusing on technical personnel evaluation, code to help enterprises quickly identify technical personnel: Candidates to accept online testing challenges, the use of machine automatic volume, programming data collection, The use of advanced technology capability recognition algorithm, accurately identify the candidate's real technical ability, the formation of a comprehensive programming skills assessment report and Analysis matrix, the results of feedback to users and companies, greatly saving time and effort. In addition, the Ape Circle self-developed Android, iOS online cloud compiler engine, can support users in the cloud (browser) to write code, in the world leading position. ";    [Self.view Addsubview:_oxtextview];
#import "OXTouchTextView.h"@implementationOxtouchtextview- (ID) initWithFrame: (CGRect) frame { self=[Super Initwithframe:frame]; if(self) {}returnSelf ;}- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event {    // the//start writing code, when the touch operation starts, gets the word that the character of the current touch position belongs to. and display it with Uialertview (hint: Touch position needs to be adjusted down by 10 points to align with the text element)Uitouch *touch =[touches anyobject]; Cgpoint TouchPoint=[Touch locationinview:self]; Nsinteger Characterindex=[Self.layoutmanager characterindexforpoint:touchpoint InTextContainer:self.textContainer    Fractionofdistancebetweeninsertionpoints:null]; if(characterindex<self.text.length) {nsstring*s=[self.text Substringwithrange:nsmakerange (Characterindex,1)]; NSLog (@"%@", s); }        //End_code[Super Touchesbegan:touches Withevent:Event];}@end

Test results:

Touch Uitextview to find the text of the touch point

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.