iOS btn实现collectionView方法

 

        NSArray * name = @[@"1",@"2",@"3",@"4"];

        for (int i = 0; i<name.count; i++) {

            UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(20+i%(name.count-1)*100, i/(name.count-1)*35, 80, 30)];

            btn.backgroundColor = [UIColor purpleColor];

            [btn setTitle:name[i] forState:UIControlStateNormal];

            [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

            [btn setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];

            [btn addTarget:self action:@selector(cilck:) forControlEvents:UIControlEventTouchUpInside];

            btn.tag = i+20;

            [self.view addSubview:btn];

        }

 

posted @ 2016-08-30 10:46  tongyuling  阅读(123)  评论(0编辑  收藏  举报