简体   繁体   English

使用Swift在xcode 6中为ios app添加背景

[英]Adding background to ios app in xcode 6 using Swift

I am new to ios development so please forgive me. 我是ios开发的新手,请原谅我。 I am taking it step by step and I was wondering how would I make a image I want to be the background in the view controller so I can add on top of it? 我正在逐步采取它,我想知道如何制作一个图像,我想成为视图控制器中的背景,以便我可以添加它?

If you want to do it programmatically using swift here is the code: 如果你想以编程方式使用swift这里是代码:

 self.view.backgroundColor = UIColor(patternImage: UIImage(named: "yourImage.png"))

Or you can create a uiimage and place your image in it: 或者您可以创建一个uiimage并将图像放入其中:

let yourImage = UIImage(named: "yourImage.png")
let imageview = UIImageView(image: yourImage)
self.view.addSubview(imageview)

Add a UIImageView to your view controller's view. 将UIImageView添加到视图控制器的视图中。 Assign your background image to the image view. 将背景图像指定给图像视图。 You can do all this in the storyboard file. 您可以在storyboard文件中执行所有这些操作。

Good luck! 祝好运!

I prefer to adding a UIImageView and setting it as background. 我更喜欢添加UIImageView并将其设置为背景。

override func viewDidLoad() {
    let backgroundImage = UIImageView(frame: UIScreen.mainScreen().bounds)
    backgroundImage.image = UIImage(named: "bg_image")
    self.view.insertSubview(backgroundImage, atIndex: 0)
}

Because I found the following code make the image a little blurry. 因为我发现以下代码使图像有点模糊。

override func viewDidLoad() {
    self.view.backgroundColor = UIColor(patternImage: UIImage(named: "yourImage.png"))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM