#import "ViewController.h"
@interface Viewcontroller ()
{
UIView *_gee; The defined instance variable
UIView *_red;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
cgrect ret = CGRectMake (+,--); A rectangular coordinate and a length-width
_gee = [self Creatview:ret color:[uicolor Greencolor]]; Call the following function to make the rectangle color green
cgrect Ret1 = CGRectMake (200, 200, The The coordinates of the other rectangle are long-width
_red = [self Creatview:ret1 color:[uicolor Redcolor ]];//Rectangle color is red
}
-(UIView *) Creatview: (cgrect) ret color: (Uicolor *) colol{//Set the name of the rectangle and the structure of the color
UIView *v = [[UIView alloc] initwithframe:ret];//The matrix is initialized with a pointer to V,
V.BACKGROUNDCOLOR = Colol;//The background color of this matrix is represented by a color method
[Self.view addsubview:v]; Let the color of the setting show up on the monitor
return v;
}
-(Ibaction) Biand: (ID) Sender {//This is a key method
[Self.view exchangesubviewatindex:3 withsubviewatindex:4]; Using array methods to exchange two matrices successively
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
@end
Two rectangles that iOS does intersect