zoukankan      html  css  js  c++  java
  • 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]; 

    }

  • 相关阅读:
    intellij idea 注册码
    python 爬虫
    打油诗
    vux 新建移动app步骤
    ubuntu支持中文配置
    pandas DataFrame 交集并集补集
    API精准定位IP地址
    Python获取本地位置和天气
    nginx配置uwsgi
    django ORM model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct
  • 原文地址:https://www.cnblogs.com/Ewenblog/p/3884336.html
Copyright © 2011-2022 走看看