Mike
Mike

Reputation: 3276

swift: Get height of any element (iOS 9)

How do I get the current height of any element using swift 2?

Any element would be: Buttons, UIImageViews, Labels, Navigation Bars, etc.

Upvotes: 3

Views: 4182

Answers (1)

Tim Vermeulen
Tim Vermeulen

Reputation: 12562

let view = UIView(frame: CGRect(origin: zero, size: CGSize(width: 10, height: 20)))
print("height = \(view.frame.height)") // prints "height = 20"

All elements you listed inherit from UIView, so they all have a frame property, which has a height property.

Upvotes: 3

Related Questions