码迷,mamicode.com
首页 > 其他好文 > 详细

让UILabel具有链接功能,点击后调用safari打开网址

时间:2015-01-24 21:12:36      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

 

 


  UILabel *labelGovUrl = [[UILabel alloc] initWithFrame:CGRectMake(73.0, 330.0, 180.0, 40.0)];

    labelGovUrl.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);

    labelGovUrl.text = @"appStore";

    labelGovUrl.backgroundColor = [UIColor clearColor];

    labelGovUrl.textColor = [UIColor blackColor];

    labelGovUrl.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];

    labelGovUrl.userInteractionEnabled = YES;

    labelGovUrl.tag = k_NNGOV_WEBSITE_LABEL_URL;


 UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openURL:)] autorelease];

    [labelGovUrl addGestureRecognizer:tapGesture];

    [self.window addSubview:labelGovUrl];

    [labelGovUrl release];


-(void)openURL:(UITapGestureRecognizer *)gesture

{

    NSInteger tag = gesture.view.tag;

    NSString *url = nil;

    if (tag == k_NNWEIBO_LABEL_URL

    {

        url = @"http://t.qq.com/yourgame/";

    }

    if (tag == k_NNGOV_WEBSITE_LABEL_URL

    {

        url = @"http://www.zjnn.cn/";

    }

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

}

让UILabel具有链接功能,点击后调用safari打开网址

标签:

原文地址:http://www.cnblogs.com/allanliu/p/4246518.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!