ios scrollView 使用Snapkit 布局

let view1 = UIView();
        scrollView.addSubview(view1);
        view1.backgroundColor = UIColor.blue;
        scrollView.backgroundColor = UIColor.red;
        view1.snp.makeConstraints { (ConstraintMaker) in
            //表示距离scrollView 他的20
            ConstraintMaker.top.equalTo(20);
            /*这里表示是整个屏幕
             如果写scrollView会没有width,在scrollView里面width是不能自动的添加的,所以需要写绝对的width
             或者使用外部的
             */
            ConstraintMaker.left.right.equalTo(view);
            ConstraintMaker.height.equalTo(1000);
            //这个非常重要,必须有,这个是控制scrollView里面内容大小的,如果内容大于scrollView的显示高度,则有滚动条
            ConstraintMaker.bottom.equalTo(scrollView);
        }
       
        scrollView.snp.makeConstraints { (ConstraintMaker) in
            ConstraintMaker.top.equalTo(64);
            //确定scrollView的宽度
            ConstraintMaker.left.right.equalTo(view);
            //确定scrollView显示的高度
            ConstraintMaker.bottom.equalTo(view);
         
        }

猜你喜欢

转载自blog.csdn.net/hjtk009/article/details/89915208
今日推荐