Objective-c for 循环 九宫格
2015-12-15 00:00
543 查看
#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
@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
相关文章推荐
- java ObjectInputStream学习小记
- object is not afunction错误
- object-c定义属性与成员变量的区别
- Objective-C 数组一 "不可变数组"
- 【转】Objective-C Runtime 消息机制
- IOS开发之NSDictionary里setValue:forKey与setObject:forKey、objectForKey与valueForKey的差异
- Java Object Model(一)
- 由NSObject学到的一点基本知识
- object-c(oc)内存管理机制详解
- 关于PinnedHeaderExpandableListView使用的时候on a null object reference
- Java Socket编程中使用ObjectOutputStream 和 ObjectInputStream 出现问题
- [转]在 Ubuntu 中使用 GNUstep 搭建 Objective-C 开发环境
- Objective-C 引用计数:不讲用法,只说原理
- 借鉴 C# 关于 LINQ 的设计思想用 C++ 11 来实现 LINQ to Object
- Objective-C AES128 Encrypt And Decrypt
- Android属性动画的学习_ObjectAnimator
- WaitForSingleObject 结束线程
- Objective-C Runtime
- 黑马程序员---Java基础---Object类
- android JSON获取值String无法转换成JSONObject