Alejo Next Alejo Next - 8 months ago 66
iOS Question

The width a element in swift

Well, i need the size a element in swift. Bat this...

let screenSize: CGRect = UIScreen.mainScreen().bounds
print(grid.frame.size.width, screenSize.width)
// 560.0 414.0

In the storyboard

+ Grid
+ Constrains
+ Grid.leading = leadingMargin
+ Grid.bottom = Bottom Layout
+ = top
+ Grid.trailing = leadingMargin

How do you capture the width (real) the element for Grid?


Your question is very vague but here is what I see:

  1. Your constraints don't seem right in any case. Why does grid have trailing to leadingMargin? Shouldn't it be trailing to trailingMargin?
  2. When using autolayout, frames do not automatically have their correct size, try adding this code before accessing a frame dimensions:


    This way, an autolayout pass is forced, allowing the frames to be set.