I am making a very simple single view application in Swift (XCode 6.2) that comprises of 2 buttons "blackButton" and "whiteButton". Upon clicking blackButton it changes the View's background color to Black and upon clicking the whiteButton it changes the background to white. Can anyone suggest any possible ways to do this?
//beginning
import UIKit
class ViewController: UIViewController {
@IBAction func blackButton(sender: AnyObject) {
}
@IBAction func whiteButton(sender: AnyObject) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
A view controller's view can be accessed through it's view
property, which is just a regular UIView
. UIView
's have a backgroundColor
property, which is a UIColor
and controls the color of the view.
@IBAction func blackButton(sender: AnyObject) {
view.backgroundColor = .black
}
@IBAction func whiteButton(sender: AnyObject) {
view.backgroundColor = .white
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments