0

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

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

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

1 Answer 1

1

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:

    grid.setNeedsLayout()
    grid.layoutIfNeeded()
    

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.