Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS swift View.frame.width is wrong

Hello i try to get the width of a UIView Element.

I tested it on an Iphone 4s Emulator.

I have an UIView Element on the main screen. Wich has 20 offset on the left and the right site of the screen.

When i call

UIScreen.mainScreen().bounds.width = 320

but

viewGame.frame.width = 240

but width of viewGame should be 260 so how do i get the real frame width ?

Edit: i am using autolayout to align the view

like image 377
Tom Deng Long Avatar asked Mar 18 '16 22:03

Tom Deng Long


1 Answers

sorry for bothering. Just after posting this question i found the solution in this post

The problem is that i was calling my functions in the viewDidLoad() function in the view controller. But at this time the layouts havent been aranged yet. Now i call my functions in the viewDidAppear() function and everything works fine

like image 57
Tom Deng Long Avatar answered Nov 18 '22 21:11

Tom Deng Long