Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> iOS

Lấy kích thước (dimensions) của View trong iOS App

Kích thước view truy cập qua view.frame.size (width, height).

@IBOutlet var sampleView: UIView!

override func viewDidLoad() {
  super.viewDidLoad()
  print(sampleView.frame.size)  // in ra (width, height)
}

Lưu ý: frame tính theo tọa độ superview, bounds là tọa độ nội bộ.