Background Color Change

code post later

b-g-c

Advertisements

Table View Part-2

// Created by MohammadAzmalHossain on 11/19/16.


import UIKit

class ViewController: UIViewController, UITableViewDataSource {
 let devCourse = [("ios app development with swift training","simon allardice"),("ios 8 SDK new features","Lee BrimeLow"),("Data visualization with D3.js","Ray Villaglobos"),("swift essential training","simon allardice"),("Up and Running with AngularJS","Dan Gookin"),("MySQL Essential Training","Scott Simpson"),("Building Adaptive andraid apps with franments","David Gassner")]
 func numberOfSections(in tableView: UITableView) -> Int {
 return 1
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return devCourse.count
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 let (courseTitle, courseAuthor) = devCourse[indexPath.row]
 cell.textLabel?.text = courseTitle
 return cell
 
 
 }
 
 
 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.
 }


}

Table View

// Created by MohammadAzmalHossain on 11/19/16.
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
 func numberOfSections(in tableView: UITableView) -> Int {
 return 1
 }
 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
 return 5
 }
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = UITableViewCell()
 cell.textLabel?.text = "Hello World"
 return cell
 }
 
 
 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.
 }
}

Picker View

Picker View

/* here shows how PickerView works. can change background color by selecting on pickerView  */

// Attach Outlets -> dataSource and delegate with view-controller

screen-shot-2016-11-20-at-12-42-14-am

// Created by Nazmul Hasan on 11/19/16.


import UIKit

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
 
 let moodArray = ["happy","good","better","bad","sad","well","red","green","great","pretty","yellow","nice","cyan","beautiful"]
 
 func numberOfComponents(in pickerView: UIPickerView) -> Int {
 return 1 // indicate pickerView list
 }
 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
 return moodArray.count   // indicate row list
 }
 func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
 return moodArray[row]    // indicate array print system
 }
 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
 // it makes background color according to select in row
 
 var newBackGroundColor : UIColor
 
 switch row {
 case 5,8,9,11,13:
 newBackGroundColor = UIColor.lightGray
 case 0...4:
 newBackGroundColor = UIColor.darkGray
 case 6:
 newBackGroundColor = UIColor.red
 case 7:
 newBackGroundColor = UIColor.green
 case 10:
 newBackGroundColor = UIColor.yellow
 case 12:
 newBackGroundColor = UIColor.cyan
 
 default:
 newBackGroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
 }
 self.view.backgroundColor = newBackGroundColor 
// view indicate background
 
 }
 
 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.
 }

}

Time Display

// Created by Azmal Hossain on 11/17/16.
import UIKit

class ViewController: UIViewController{
 
@IBOutlet weak var displayTimeLabel: UILabel!

// @IBAction func refreshButton(_ sender: UIButton){
 @IBAction func refreshButton(_ sender: AnyObject) {
 let now = NSDate()
 let formatter = DateFormatter()
 formatter.dateFormat = "HH:mm:s a"  //HH-mm-s this way also can
 
 displayTimeLabel.text = formatter.string(from: now as Date)
 
}
 
 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.
 }
}

Keyboard, textField and label disappear

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {
 
 func textFieldShouldReturn(_ textField: UITextField) -> Bool {
 textField.resignFirstResponder()
 return false
 }
 @IBOutlet weak var writeYouNameTextField: UITextField!
 
 @IBOutlet weak var displayLabel: UILabel!
 
 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
 self.view.endEditing(true)
 }
 
@IBAction func enterButton(_ sender: UIButton) {
 displayLabel.text = "hello " + writeYouNameTextField.text! + "!"
 self.writeYouNameTextField.resignFirstResponder()
 writeYouNameTextField.text = ""
 }

 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.
 }
}