zoukankan      html  css  js  c++  java
  • 让UILabel具有链接功能,点击后调用safari打开网址

     


      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]];

    }

  • 相关阅读:
    binder机制理解
    Android 资源目录
    Andriod 构建项目流程
    dpi、ppi 、dp、sp、px、 pt相关概念
    短语、直接短语和句柄
    MySql优化
    java虚拟机内存管理
    redis
    linux——nginx的安装及配置
    linux——高级文本处理命令之wc、cut、sort
  • 原文地址:https://www.cnblogs.com/allanliu/p/4246518.html
Copyright © 2011-2022 走看看