Search code examples
swiftcgrectcgsize

UILabel get Frame width or height


`lblAddress.frame.width`
`lblAddress.frame.size.width`

I have searched so many time but still i haven't point out...what is difference between lblAddress.frame.width AND lblAddress.frame.size.width. it gives me same output..I don't know which one to use when?

please suggest some example so I can figure out whole thing.


Solution

  • They are (almost) the same. One is width of CGRect, the other one is width of CGSize.

    The only difference is that frame.width will always return positive values, as frame.size.width may return in some circumstances negative values.

    I would use the shorthand frame.width directly if I only care about standardized geometry.