Objective-c for 循环 九宫格

我们两清 提交于 2019-11-30 00:02:31


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    [self ninePic];

    // Do any additional setup after loading the view, typically from a nib.

}


-(void)ninePic

{

    NSMutableArray *_imageArr = [NSMutableArray arrayWithCapacity:10];

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

        for (int j = 0; j < 3; j++) {

            CGRect rect = CGRectMake(18.75+j*118.75, 200+i*118.75, 100, 100);

            UIImageView *imageView = [[UIImageView alloc]initWithFrame:rect];

            imageView.backgroundColor = [UIColor purpleColor];

            [self.view addSubview:imageView];

            [_imageArr addObject:imageView];

        }

    }

    NSLog(@"%@", _imageArr);

    UIImageView *iv = (UIImageView *)_imageArr[4];

    iv.backgroundColor = [UIColor redColor];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!