现在的位置: 首页 > 综合 > 正文

在UILable上添加点击事件

2014年10月11日 ⁄ 综合 ⁄ 共 532字 ⁄ 字号 评论关闭

朋友问怎么给UILable像button一样做点击事件,顺便写了下,如下 :

第一步,将UILable的userInteractionEnabled值设置为YES,这样才能触发点击事件。

第二步,通过TapGestureRecognize注册事件。

代码如下:

- (void)viewDidLoad

{

    [super
viewDidLoad];

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

    [m_lable
addGestureRecognizer:tapGesture];

}

-(void)onClickLable

{

    UIAlertView *alertView = [[[UIAlertView
alloc]initWithTitle:nil
message:@"fdfdfdf"
delegate:nil
cancelButtonTitle:@"N"
otherButtonTitles:@"Y",
nil] autorelease];

    [alertView show];

}

抱歉!评论已关闭.