您的位置:首页 > 产品设计 > UI/UE

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

2015-01-24 20:23 363 查看

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: