S.Verma S.Verma - 9 months ago 29
iOS Question

How do I put an UIImageView in the center of a tableView

I want my image to be in the center in the x axis, I'm writing this code :

let emptyImage=UIImageView(frame: CGRect(x: (UIScreen.main.bounds.width)/2 ,y: 200 , width: 50, height: 50))


but it doesn't work.

Answer Source

try this

let emptyImage = UIImageView(frame: CGRect(x: UIScreen.main.bounds.width/2 - 50/2, y: 200, width: 50, height : 50)