Ios UITextView可点击,几乎像UIButton一样
我有一个Ios UITextView可点击,几乎像UIButton一样,ios,Ios,我有一个UITextView,里面有很多文本,并根据需要定制了它。我想知道,有没有办法让它可以点击,然后导航到一个新的UIViewController 我在搜索这个,似乎唯一的方法是让一个不可见的ui按钮覆盖它?您可以在您的文本视图中添加一个UIAPTgestureRecograiser。无论是在界面生成器中,还是在代码中 UITapGestureRecogniser *tap = [[UITapGestureRecognizer alloc] initWithTarget:self actio
UITextView
,里面有很多文本,并根据需要定制了它。我想知道,有没有办法让它可以点击,然后导航到一个新的UIViewController
我在搜索这个,似乎唯一的方法是让一个不可见的
ui按钮覆盖它?您可以在您的文本视图中添加一个UIAPTgestureRecograiser。无论是在界面生成器中,还是在代码中
UITapGestureRecogniser *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myfunction:)]:
[mytextview addGestureRecogniser:tap];
[mytextview setEditable:NO];
[mytextview setUserInteractionEnabled:YES];
[tap release];
编辑:谢谢Nekto您可以在文本视图中添加UITapGestureRecograiser。无论是在界面生成器中,还是在代码中
UITapGestureRecogniser *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myfunction:)]:
[mytextview addGestureRecogniser:tap];
[mytextview setEditable:NO];
[mytextview setUserInteractionEnabled:YES];
[tap release];
编辑:感谢NektoUITextView
没有声明选择器AddGestureRecognitizer
,因此我使用此选项:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textViewTapped:)];
NSArray *gestureRecognizers = [NSArray arrayWithObject:tap];
[textView setGestureRecognizers:gestureRecognizers];
[textView setEditable:NO];
[textView setUserInteractionEnabled:YES];
UITextView
没有声明选择器addgestureRecognitizer
,因此我改用它:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textViewTapped:)];
NSArray *gestureRecognizers = [NSArray arrayWithObject:tap];
[textView setGestureRecognizers:gestureRecognizers];
[textView setEditable:NO];
[textView setUserInteractionEnabled:YES];
使用界面生成器,可以将TextView类设置为UIControl。然后,您可以控制从它到任何iAction的拖动。使用界面生成器,您可以将TextView类设置为UIControl。然后,您可以控制从它到任何iAction的拖动。为什么不想让一个不可见的UIButton覆盖它?这不是正确的方式,不想在GUI上不必要地增加太多的权重。为什么不想让一个不可见的UIButton覆盖它?这不是正确的方式,不要不必要地过分强调GUI。+不要忘记禁用编辑UITextView
但启用userInteraction
+不要忘记禁用编辑UITextView
但启用userInteraction