UIView *blackV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HIGHT)]; blackV.backgroundColor = [UIColor colorWithRed:122/255.0 green:123/255.0 blue:234/255.0 alpha:0.7]; [self.view addSubView: blackV]第二種方案:
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur]; effectview.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_WIDTH + 30); effectview.contentView.backgroundColor = [UIColor greenColor]; if (IOS8) { [self.view addSubview:self.effectview]; self.backgroundColor = RGB_COLOR(80, 80, 80); self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"princess"]]; }else{ self.backgroundColor = RGBA_COLOR(20, 20, 20, .7); self.backgroundColor = [UIColor whiteColor]; }
這段代碼是在以後視圖控制器上添加了一個UIImageView作為背景圖
ViewController2 *lagerPicVC = [[ViewController2 alloc]init]; self.modalPresentationStyle = UIModalPresentationCurrentContext;//關鍵語句,必需有 [self presentViewController:lagerPicVC animated:YES completion:nil]; [self.view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.868f]];
視圖2(ViewController2)中設置背景通明度
【iOS設置父視圖通明度而不影響子視圖】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!