Objective-C-iOS UIScrollView UIPageControl 的用法详解

来源:互联网 发布:淘宝有客服电话 编辑:程序博客网 时间:2024/06/09 18:49

- (void)viewDidLoad {

    [superviewDidLoad];


    //UIView是视图类,所有的控件都直接或间接地继承它

    

    //创建UIView

    UIView *view1 = [[UIViewalloc] init];

    UIView *view2 = [[UIViewalloc] initWithFrame:CGRectMake(20,120, 100,100)];

    UIView *view3 = [[UIViewalloc] initWithFrame:CGRectMake(40,140, 100,100)];

    //设置view的尺寸

    view1.frame =CGRectMake(0,100, 100,100);

    

    //设置view的背景色

    view1.backgroundColor = [UIColorredColor];

    view2.backgroundColor = [UIColorgreenColor];

    view3.backgroundColor = [UIColorblueColor];

    

    //设置view的中心位置,不改变view的大小

//    view1.center = CGPointMake(80, 200);

    

    //改变view的宽和高,视图原来的中心位置不变

//    view1.bounds = CGRectMake(0, 0, 40, 40);

    

    //设置viewtag

    view1.tag =1;

    view2.tag =2;

    view3.tag =3;

    

    //依次添加三个视图(从上到下是:蓝,绿,红)

    [self.viewaddSubview:view1];

    [self.viewaddSubview:view2];

    [self.viewaddSubview:view3];

    

    //view1(红)移到最上面

    [self.viewbringSubviewToFront:view1];

    

    //view3(蓝)移到最下面

    [self.viewsendSubviewToBack:view1];

    

    //还有很多用来交换两个视图的方法,这里不再一一列举

    /*

     //交换两个视图的位置

     //    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

     //把一个视图插在某个位置

    - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;

    //把一个视图插在另一个视图的下面

    - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

     //把一个视图插在另一个视图的上面

    - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

    //已经添加了某个视图

    - (void)didAddSubview:(UIView *)subview;

     //将要移除某个视图

    - (void)willRemoveSubview:(UIView *)subview;

    //把一个视图从一个父视图上移到另一个父视图上

    - (void)willMoveToSuperview:(nullable UIView *)newSuperview;

     //已经移动到了父视图上

    - (void)didMoveToSuperview;

     //把一个视图移动到一个窗口上

    - (void)willMoveToWindow:(nullable UIWindow *)newWindow;

     //已经移动到了一个窗口上

    - (void)didMoveToWindow;

    

    */

    //subViews中存放的(红,绿,蓝三个视图)

    NSArray *subViews =self.view.subviews;

    

    //如何找到一个视图,其实此时view4就是view1,view5也是view1

    UIView *view4 = [subViewsobjectAtIndex:0];

    view4.backgroundColor = [UIColorblackColor];

    UIView *view5 = (UIView *)[self.viewviewWithTag:1];

    view5.backgroundColor = [UIColorpurpleColor];

    

    //隐藏view1

    view1.hidden =YES;

    

    //删除View2

    [view2 removeFromSuperview];

    

    //再添加一个视图

    UIView *lastView = [[UIViewalloc] initWithFrame:CGRectMake(0,200, 200,200)];

    lastView.backgroundColor = [UIColorcolorWithWhite:0.8alpha:1];

    [self.viewaddSubview:lastView];

    

    //设置view的透明度

    lastView.alpha =0.5;

    

    //设置lastView的圆角角度

    lastView.layer.cornerRadius =10;

    //设置边框的的宽度

    lastView.layer.borderWidth =2;

    //设置边框的颜色

    lastView.layer.borderColor = [UIColorredColor].CGColor;

    //允许剪切

    lastView.clipsToBounds =YES;

}


0 0
原创粉丝点击