难点:
1.UIView的继承和隐藏;
2.UIView的层级关系;
3.创建3个UIView,1个为父视图,2个为子视图,设置他们的显示关系;
复习次数:3次
5月13日
5月16日
5月31日
源代码:
- (void)viewDidLoad {
[super viewDidLoad];
UIView *vc=[[UIView alloc ]initWithFrame:CGRectMake(10, 10, 100, 200)];
vc.backgroundColor=[UIColor yellowColor];
vc.tag=101;
[self.view addSubview:vc];
UIView *vc2=[[UIView alloc ]initWithFrame:CGRectMake(0, 0, 50, 50)];
vc2.backgroundColor=[UIColor redColor];
vc2.tag=102;
[vc addSubview:vc2];
UIView *vc3=[[UIView alloc ]initWithFrame:CGRectMake(50, 50, 50, 50)];
vc3.backgroundColor=[UIColor blackColor];
vc3.tag=103;
[vc addSubview:vc3];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(50, 250, 80, 40);
[btn setTitle:@"隐藏视图3" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)hide
{
UIView *hideView=[[UIView alloc]init];
hideView=[self.view viewWithTag:103];
hideView.hidden=YES;
UIView *hideView2=[[UIView alloc]init];
hideView2=[self.view viewWithTag:102];
hideView2.alpha=0.5;
}