zoukankan      html  css  js  c++  java
  • label添加手势(触摸改变其背景颜色)

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

        

        

    }

  • 相关阅读:
    getopt for windows
    开源代码学习之Tinyhttpd
    GCC 中的编译器堆栈保护技术
    读《程序员的思维修炼》有感
    main之前初始化流程
    平均速度
    显示图案
    圆的面积和周长
    C#(Winform) Http 发送数据
    Android BaseAdapter的使用
  • 原文地址:https://www.cnblogs.com/thbbsky/p/3750111.html
Copyright © 2011-2022 走看看