朋友问怎么给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];
}