Objective-C UILabel作为HyperLink [英] Objective-C UILabel as HyperLink

查看:97
本文介绍了Objective-C UILabel作为HyperLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 UIWebView 创建 UILabel 链接。如何使 UILabel 作为超链接工作?

I am trying to make a UILabel a link for a UIWebView. How can I make a UILabel to work as hyperlink?

推荐答案

你可以使用UITapGestureRecognizer,它可以运行你想要的类似东西 -

You can go for UITapGestureRecognizer, that will work something similar that you want -

UILabel *myLabel = [[UILabel alloc] initWithFrame:];//Define label here as per needs
myLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];
[myLabel addGestureRecognizer:gr];
gr.numberOfTapsRequired = 1;
gr.cancelsTouchesInView = NO;
[self.view addSubview:myLabel];

现在采取行动 -

- (void) myAction: (UITapGestureRecognizer *) gr {
    // Define actions here
}

这篇关于Objective-C UILabel作为HyperLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆