废话少说,先上图:
对应的代码:
UIImageView *imgView = [[UIImageViewalloc]initWithFrame:self.view.bounds];
imgView.image = [UIImageimageNamed:@"pgn.jpg"];
imgView.contentMode =UIViewContentModeScaleAspectFit;
imgView.center =self.view.center;
[self.viewaddSubview:imgView];
//设置背景图片,全屏
UIView *pview = [[UIViewalloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH/2, SCREEN_HEIGHT)];
pview.backgroundColor = [UIColorblueColor];
[self.viewaddSubview:pview];
//设置测试view 左半屏 底色蓝色
修改代码,效果如下:
代码:
UIImageView *imgView = [[UIImageViewalloc]initWithFrame:self.view.bounds];
imgView.image = [UIImageimageNamed:@"pgn.jpg"];
imgView.contentMode =UIViewContentModeScaleAspectFit;
imgView.center =self.view.center;
[self.viewaddSubview:imgView];
//设置背景图片,全屏
UIView *pview = [[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH/2, SCREEN_HEIGHT)];
pview.backgroundColor = [UIColor blueColor];
[self.view addSubview:pview];
//设置测试view 左半屏 底色蓝色
UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH/2 ,SCREEN_HEIGHT/2) ];
subview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
pview.maskView =subview;
//测试view 增加maskView,左上部屏
分析:
view设置了maskView后,那么它只会显示与maskView重叠部分,即在此图中只会显示maskView部分的上半部分,与maskView的底色无关,但无底色又不可以,maskView的alpha值影响显示的效果,为0时 view 和maksView都不显示,为1时 直接显示view在底色,介于0和1时,显示蒙版的效果。