如何在swift的状态栏下居中图像?

Xco*_*OOB 3 xcode image center swift

我似乎无法找到合适的代码.我想在状态栏下放置20个图像(这将是Y)并将其居中(当然这将是X).我可以轻松地使用故事板来完成它,但我正在努力以编程方式进行.我认为这是我的代码:

var image: UIImage = UIImage(named: "someImage.png")!
            var bgImage = UIImageView(image: image)
            //Tried with self.view.frame.size.height but not working
            bgImage.frame = CGRect(x: 0, y: self.view.frame.size.height - 20, width: self.view.frame.size.width, height: 64)

           //also tried this which not worked as well 
          //  bgImage.center = CGPointMake(self.view.frame.width, self.view.frame.hight - 20)
            self.view.addSubview(bgImage)
Run Code Online (Sandbox Code Playgroud)

我已经搜索了苹果文档,但它很不清楚,任何帮助都会受到赞赏.

Jef*_*mas 9

Once bgImage has the correct size, then the general solution for this is

bgImage.frame.origin.y = 20.0 // 20 down from the top
bgImage.frame.origin.x = (self.view.bounds.size.width - bgImage.frame.size.width) / 2.0 // centered left to right.
Run Code Online (Sandbox Code Playgroud)