Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bounds.size.width and bounds.width in swift?

Tags:

ios

swift

What is the difference between bounds.size.width and bounds.width in swift? Will they return the same thing? Thanks!

like image 793
JDG Avatar asked Mar 17 '23 08:03

JDG


1 Answers

bounds is a CGRect struct property for a UIView that contains 2 nested structs within it; CGPoint and CGSize. These represent the points of origin for the view (x and y), and the size of the view in height and width specified in points respectively.

If you have a UIView that's 100 x 100, then: bounds.width will return 100, and bounds.size.width will also return 100. Basically they will return the same CGFloat values even if your CGRect has negative width and height values.

like image 54
Aaron Avatar answered Apr 24 '23 22:04

Aaron