butter_baby butter_baby - 4 months ago 12
Swift Question

How can I make it so that my UIView is always flush with the right side of my screen without autolayout?

I am trying to get my UIView to always stay on the right hand side of the screen:

let yPosition: CGFloat = UIApplication.sharedApplication().statusBarOrientation.isPortrait ? 54.0 : 38.0
self.customView = CustomView(frame: CGRectMake(0, yPosition, 255, 306.8))
self.view.addSubview(self.customView!)

Answer

Try this:

let yPosition: CGFloat = UIApplication.sharedApplication().statusBarOrientation.isPortrait ? 54.0 : 38.0
self.customView = CustomView()
self.customView!.frame.size = CGSize(width: 255, height: 306.8)
self.customView!.frame.origin = CGPointMake(self.view.frame.size.width - self.customView!.frame.size.width, yPosition)
self.view.addSubview(self.customView!)
Comments