IOS swift View.frame.width is wrong
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