본문 바로가기
iOS

Swift translatesAutoresizingMaskIntoConstraints 설정하기

by 정석 지향 2020. 9. 10.
반응형

  let cv = UIView(frame: CGRect(x: 100, y: 100, width: 400, height: 400))

    cv.translatesAutoresizingMaskIntoConstraints = false

    cv.backgroundColor = .red

    self.view.addSubview(cv)

    

    cv.widthAnchor.constraint(equalToConstant: 50).isActive = true

    cv.heightAnchor.constraint(equalToConstant: 50).isActive = true

 

    cv.topAnchor.constraint(equalTo: self.view.topAnchor,constant: 100).isActive = true

    cv.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,constant: 100).isActive = true

좌 - cv. translatesAutoresizingMaskIntoConstraints  =  false     

 우 - cv. translatesAutoresizingMaskIntoConstraints  =  true

반응형