发布网友
发布时间:2022-04-22 07:32
共2个回答
热心网友
时间:2022-06-17 19:03
版权声明:本文为博主原创文章,未经博主允许不得转载。
for (int>0;>3; i++) {
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(30*i, 30*i+50, 80, 80)];
v.backgroundColor =[[UIColor alloc] initWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:arc4random()%1001/999.0];
[self.window addSubview:v];
[v release];
}
UIView *v =[[UIView alloc] initWithFrame:CGRectMake(20, 20, 20, 80)];
v.backgroundColor =[UIColor yellowColor];
//插入子视图 index就是数组的下标 (实际上是在self.window.subview 视图中添加子视图)
[self.window insertSubview:v atIndex:1];
//插入子视图 放在某视图上面
UIView *v1 =[[UIView alloc] initWithFrame:CGRectMake(40, 20, 20, 70)];
v1.backgroundColor = [UIColor orangeColor];
[self.window insertSubview:v1 aboveSubview:self.window.subviews[2]];
//插入子视图 放在某视图下面
UIView *v2 =[[UIView alloc] initWithFrame:CGRectMake(0, 20, 20, 100)];
v2.backgroundColor = [UIColor greenColor];
[self.window insertSubview:v2 belowSubview:self.window.subviews[0]];
//把某视图置顶(不进行插入)调用完毕后 该视图在最顶层
[self.window bringSubviewToFront:self.window.subviews[3]];
//把某视图置底(不进行插入)调用完毕后 盖世兔在最底层
[self.window sendSubviewToBack:self.window.subviews[5]];
//某视图交换位置后 索引值也会发生变化
//把某个视图调换位置
[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:4];
//判断视图是否是另一个视图的子视图
NSLog(@"%d",[self.window.subviews[0] isDescendantOfView:self.window]);
热心网友
时间:2022-06-17 19:04
{ //1 创建scrollView CGFloat scrollViewWidth = 600;//scrollView宽度 CGFloat scrollViewHeight = 200;//scrollView高度 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, scrollViewWidth, scrollViewHeight)]; //2 将scrollView添加到当前视图 [view addSubview:scrollView]; //3 在scrollView中添加子视图 UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, scrollViewHeight)]; subView1.backgroundColor = [UIColor redColor]; [scrollView addSubview:subView1];UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, scrollViewHeight)]; subView2.backgroundColor = [UIColor greenColor]; [scrollView addSubview:subView2];UIView *subView3 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, scrollViewHeight)]; subView2.backgroundColor = [UIColor greenColor]; [scrollView addSubview:subView2];}