`
yourgame
  • 浏览: 352469 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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

    博客分类:
  • IOS
阅读更多
 //侬侬官网连接
    UILabel *labelGovUrl = [[UILabel alloc] initWithFrame:CGRectMake(73.0, 330.0, 180.0, 40.0)];
    labelGovUrl.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
    labelGovUrl.text = @"侬侬官网 >";
    labelGovUrl.backgroundColor = [UIColor clearColor];
    labelGovUrl.textColor = [UIColor whiteColor];
    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.view 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]];
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics