标签:style blog http io ar color os sp on
#import "ViewController.h"
@interface ViewController ()
{
UIView *_gee; //定义的实例变量
UIView *_red;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CGRect ret = CGRectMake(100, 100, 150, 150);//一个矩形的坐标 和长宽
_gee = [self creatView:ret color:[UIColor greenColor]]; //调用下面函数 让这个矩形的颜色为绿色
CGRect ret1 = CGRectMake(200, 200, 150, 150);//另一个矩形的坐标 长宽
_red = [self creatView:ret1 color:[UIColor redColor]];//矩形颜色为红色
}
-(UIView *)creatView:(CGRect)ret color:(UIColor *)colol{//设置矩形的名字还有颜色的结构
UIView *v = [[UIView alloc] initWithFrame:ret];//将这个矩阵用v的指针来初始化,
v.backgroundColor = colol;//这个矩阵的背景颜色用color方法来表示
[self.view addSubview:v];让设置的颜色在显示器上显示出来
return v;
}
- (IBAction)biand:(id)sender {//这是一个按键的方法
[self.view exchangeSubviewAtIndex:3 withSubviewAtIndex:4];//用到数组的方法交换两个矩阵先后
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
标签:style blog http io ar color os sp on
原文地址:http://www.cnblogs.com/daijiahong/p/4153992.html