그래서 나는 다음 UIKit 요소를 UIViewController에 추가하여 나타나는 시뮬레이션을 제어합니다. 나는 많은 배치 코드를 써야 할 것으로 예상했지만, 대신에 모든 것이 완벽하게 아무런 장치도 아닌 것처럼 보였다. 나의 질문은 왜 그런가?UIKitView에 객체를 추가 할 때 객체의 위치와 크기가 완벽하게 왜 왜 생깁니 까?
let menuButton = UIButton()
let statusLabel = UILabel()
let segmentedLabel = UISegmentedControl(items: ["None", "Glow", "Cloud"])
func initializeUI() {
//The menu button that opens up the options for the simulations
menuButton.layer.borderColor = UIColor.lightGray.cgColor
menuButton.layer.borderWidth = 1
menuButton.layer.cornerRadius = 5
menuButton.layer.backgroundColor = UIColor.darkGray.cgColor
menuButton.showsTouchWhenHighlighted = true
menuButton.imageView?.contentMode = UIViewContentMode.scaleAspectFit
menuButton.setImage(UIImage(named: "hamburger.png"), for: UIControlState.normal)
menuButton.addTarget(self, action: #selector(menuPress), for: UIControlEvents.touchDown)
view.addSubview(menuButton)
//Will display the status of the simulation
statusLabel.text = "Particle Simulation"
statusLabel.textColor = UIColor.darkGray
view.addSubview(statusLabel)
//Will display visual options
view.addSubview(segmentedLabel)
}
각 요소의 크기는 완벽하며 중첩되지 않습니다. 라벨은 왼쪽 하단에 있으며 버튼은 오른쪽 하단에 있으며 분할 된보기는 내 가로 앱의 왼쪽 상단에 있습니다.
나는 이러한 객체를 프로그래밍 방식으로 배치하기를 원한다면 어떻게해야할까요? 요소는 내가 작업 할 수있는 속성 위치가 없으며 메뉴 버튼을 매우 높게 만들지 않는 menuButton.frame.size.height *= 20
과 같은 것을하면됩니다.
이것은 UIKit 동작입니다. 내가 보지 못한이 효과를 만들어내는 코드가 작성되었습니다. –