首页 > 其他 > 详细

label添加手势(触摸改变其背景颜色)

时间:2014-05-26 00:02:43      阅读:424      评论:0      收藏:0      [点我收藏+]

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    UILabel *lab1=[[UILabelalloc]initWithFrame:CGRectMake(20, 30, 100, 30)];

    lab1.text=@"helloworld";

  //设置tag属性

    lab1.tag=1;

    UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(randomColor:)];

    [lab1 addGestureRecognizer:tap];

    lab1.userInteractionEnabled=YES;

    [self.window addSubview:lab1];

   

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    returnYES;

}

-(void)randomColor:(UITapGestureRecognizer *)gestureRecognizer

{

  //通过tag属性来获取label

    UILabel *lab=(UILabel *)[self.window viewWithTag:1];

    lab.backgroundColor=[UIColorcolorWithRed:arc4random()%256/255.0green:arc4random()%256/255.0blue:arc4random()%256/255.0alpha:1];

    

    

}

label添加手势(触摸改变其背景颜色),布布扣,bubuko.com

label添加手势(触摸改变其背景颜色)

原文:http://www.cnblogs.com/thbbsky/p/3750111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!