- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *redView = [[UIView alloc] init];
redView.frame=CGRectMake(0, 100, 100, 200);
redView.backgroundColor=[UIColor greenColor];
[self.view addSubview:redView];
UIView *greenView =[[UIView alloc]init];
greenView.frame=CGRectMake(100, 100, 100, 200);
greenView.backgroundColor=[UIColor redColor];
[self.view addSubview:greenView];
UIView *blackView =[[UIView alloc]init];
blackView.frame=CGRectMake(200, 100, 100, 200);
blackView.backgroundColor=[UIColor blackColor];
[self.view addSubview:blackView];
原文地址:http://www.cnblogs.com/niang123/p/3834678.html