• IOS 根据数组的个数对UIButton进行重复或循环使用


    //设置一个view 

    view = [[UIView alloc] initWithFrame:CGRectMake(0, 38, 320, 30)]; 

    view.backgroundColor = [UIColor lightGrayColor]; 

    [self.view addSubview:view]; 

    for (int i=0; i<5; i++) { 

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 

    button.tag = 100+i; 

    button.frame = CGRectMake(64*i+3, 3, 58, 25); 

    [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside]; 

    [button setTitle:[NSString stringWithFormat:@"%@",[array objectAtIndex:i]] forState:UIControlStateNormal]; 

    //默认在第一个 

    if (button.tag == 100) { 

    [button setBackgroundImage:[UIImage imageNamed:@"blueBtn.png"] forState:UIControlStateNormal]; 

    //将循环创建的button都添加到view上面 

    [view addSubview:button]; 

    #pragma mark - button触发的方法 

    -(void)doButton:(UIButton *)sender 

    for (UIButton *button in view.subviews) { 

    if (button.tag != sender.tag) { 

    [button setBackgroundImage:nil forState:UIControlStateNormal]; 

    else 

    [button setBackgroundImage:[UIImage imageNamed:@"blueBtn.png"] forState:UIControlStateNormal]; 

    }

  • 相关阅读:
    jquery属性
    jquery选择器
    Django的模型
    win7安装RabbitMQ
    阿里云RDS备份的tar格式包恢复到本地自建数据库
    正确使用 Volatile 变量
    深入分析Volatile的实现原理
    volatile和synchronized的区别
    全面理解Java内存模型
    深入理解Feign之源码解析
  • 原文地址:https://www.cnblogs.com/Ewenblog/p/3884336.html
Copyright © 2020-2023  润新知