IOS控制元件基礎UIView
阿新 • • 發佈:2018-12-15
//新建一個UIView並設定它的位置和大小 UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; //為新建的UIView設定背景顏色 view1.backgroundColor = [UIColor redColor]; //透明度 view1.alpha = 0.2; //是否隱藏 view1.hidden = YES; //設定中心點為螢幕的中心點 view1.center = self.view.center; //標籤值 view1.tag = 99; //根據標籤值找到view1,下面這個resultView就是view1 UIView *resultView = [self.view viewWithTat:99]; //將UIView放到窗體中 [self.view addSubview:view1]; //將子檢視移動到前面 [self.view bringSubviewToFront:resultView]; //將子檢視移動到後面 [self.view sendSubviewToBack:resultView]; //銷燬view1 [view1 removeFromSuperview];