images
SimpleViews
//
// ViewController.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var aTableView: UITableView!
var views = [“UIImage”, “UIImageView”, “UIScrollView”, “UIWebView”,”UIMapView”, “UIPickerView”]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “Various Views”
aTableView.delegate = self
aTableView.dataSource = self
aTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: “cell”)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return views.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: UITableViewCell = aTableView.dequeueReusableCellWithIdentifier(“cell”) as UITableViewCell!
cell.textLabel?.text = views[indexPath.row]
//cell.imageView?.image = images[indexPath.row]
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
print(cell.textLabel?.text)
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
tableView.deselectRowAtIndexPath(indexPath, animated: true)
print(“You selected cell #\(indexPath.row)”)
//let aViewController: SimpleViewController = storyboard?.instantiateViewControllerWithIdentifier(“SimpleViewController”) as! SimpleViewController
//aViewController.title = views[indexPath.row]
//navigationController?.pushViewController(aViewController, animated: true)
switch indexPath.row {
case 0:
self.performSegueWithIdentifier(“ShowSimpleVCSegue”, sender: self)
case 1:
self.performSegueWithIdentifier(“ShowSimpleVCSegue2”, sender: self)
case 2:
self.performSegueWithIdentifier(“ShowSimpleVCSegue3”, sender: self)
case 3:
self.performSegueWithIdentifier(“ShowSimpleVCSegue4”, sender: self)
case 4:
self.performSegueWithIdentifier(“ShowSimpleVCSegue5”, sender: self)
case 5:
self.performSegueWithIdentifier(“ShowSimpleVCSegue6”, sender: self)
default:
break
}
}
}
//
// SimpleViewController.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class SimpleViewController: UIViewController {
@IBAction func didTap(sender: AnyObject) {
self.performSegueWithIdentifier(“ShowSimpleVCSegue2”, sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIImage”
// programmatically (with no outlet)
//let imageView = UIImageView(frame:CGRectMake(10, 50, 100, 300))
//imageView.image = UIImage(named: “smile”)
//self.view.addSubview(imageView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//
// SimpleViewController2.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class SimpleViewController2: UIViewController {
@IBOutlet weak var aImageView: UIImageView!
@IBAction func didSwipe(sender: AnyObject) {
if aImageView.isAnimating() {
aImageView.stopAnimating()
} else {
aImageView.startAnimating()
}
}
@IBAction func didTap(sender: AnyObject) {
self.performSegueWithIdentifier(“ShowSimpleVCSegue3”, sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIImageView”
aImageView.animationImages = [
UIImage(named: “frame1”)!,
UIImage(named: “frame2”)!,
UIImage(named: “frame3”)!,
UIImage(named: “frame4”)!,
UIImage(named: “frame5”)!
]
aImageView.animationDuration = 5
aImageView.animationRepeatCount = 0
aImageView.startAnimating()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//
// SimpleViewController3.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class SimpleViewController3: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var aScrollView: UIScrollView!
var imageView: UIImageView!
var scaleFactor: Double = 1.0
func setZoomScale() {
let imageViewSize = imageView.bounds.size
print(“imageViewSize=\(imageViewSize)”)
let aScrollViewSize = aScrollView.bounds.size
print(“scrollViewSize=\(aScrollViewSize)”)
let widthScale = aScrollViewSize.width / imageViewSize.width
let heightScale = aScrollViewSize.height / imageViewSize.height
print(“widthScale=\(widthScale) heightScale=\(heightScale)”)
aScrollView.minimumZoomScale = min(widthScale, heightScale)
aScrollView.zoomScale = 1.0
}
func centerScrollViewContents() {
let boundsSize = aScrollView.bounds.size
var contentsFrame = imageView.frame
if contentsFrame.size.width < boundsSize.width {
contentsFrame.origin.x = (boundsSize.width – contentsFrame.size.width) / 2.0
} else {
contentsFrame.origin.x = 0.0
}
if contentsFrame.size.height < boundsSize.height {
contentsFrame.origin.y = (boundsSize.height – contentsFrame.size.height) / 2.0
} else {
contentsFrame.origin.y = 0.0
}
imageView.frame = contentsFrame
}
func scrollViewDoubleTapped(recognizer: UITapGestureRecognizer) {
print(“doubletapped recognizer”)
// 1
let pointInView = recognizer.locationInView(imageView)
// 2
var newZoomScale = aScrollView.zoomScale * 1.5
newZoomScale = min(newZoomScale, aScrollView.maximumZoomScale)
// 3
let scrollViewSize = aScrollView.bounds.size
let w = scrollViewSize.width / newZoomScale
let h = scrollViewSize.height / newZoomScale
let x = pointInView.x – (w / 2.0)
let y = pointInView.y – (h / 2.0)
let rectToZoomTo = CGRectMake(x, y, w, h);
// 4
aScrollView.zoomToRect(rectToZoomTo, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIScrollView”
// 1
let image = UIImage(named:”RedondoBeach”)
imageView = UIImageView(image: image)
imageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size:image!.size)
aScrollView.addSubview(imageView)
// 2
aScrollView.contentSize = image!.size
// 3
//let doubleTapRecognizer = UITapGestureRecognizer(target: self, action: “scrollViewDoubleTapped:”)
//doubleTapRecognizer.numberOfTapsRequired = 2
//doubleTapRecognizer.numberOfTouchesRequired = 1
//aScrollView.addGestureRecognizer(doubleTapRecognizer)
// 4
//let scrollViewFrame = aScrollView.frame
//let scaleWidth = scrollViewFrame.size.width / aScrollView.contentSize.width
//let scaleHeight = scrollViewFrame.size.height / aScrollView.contentSize.height
//let minScale = min(scaleWidth, scaleHeight);
//aScrollView.minimumZoomScale = minScale;
// 5
//aScrollView.maximumZoomScale = 1.0
//aScrollView.zoomScale = minScale;
setZoomScale()
// 6
//centerScrollViewContents()
aScrollView.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillLayoutSubviews() {
setZoomScale()
}
func scrollViewDidScroll(scrollView: UIScrollView) {
//let foregroundHeight = self.scrollView.contentSize.height – CGRectGetHeight(self.scrollView.bounds)
//let percentageScroll = self.scrollView.contentOffset.y / foregroundHeight
//self.scrollView.contentOffset = CGPoint(x: 0, y: foregroundHeight * percentageScroll) // vertical scrolling only
aScrollView.contentOffset = CGPoint(x: aScrollView.contentOffset.x, y: aScrollView.contentOffset.y)
}
func scrollViewDidZoom(scrollView: UIScrollView) {
let imageViewSize = imageView.frame.size
let scrollViewSize = scrollView.bounds.size
let verticalPadding = imageViewSize.height < scrollViewSize.height ? (scrollViewSize.height – imageViewSize.height) / 2 : 0
let horizontalPadding = imageViewSize.width < scrollViewSize.width ? (scrollViewSize.width – imageViewSize.width) / 2 : 0
scrollView.contentInset = UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return imageView
}
}
//
// SimpleViewController4.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class SimpleViewController4: UIViewController {
@IBOutlet weak var aWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIWebView”
let url = NSURL(string: “http://dis.dankook.ac.kr/lectures/pmd16/”)
let requestObject = NSURLRequest(URL: url!)
aWebView.loadRequest(requestObject)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//
// SimpleViewController5.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
import MapKit
import CoreLocation
class SimpleViewController5: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var aMapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIMapView”
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// location delegate
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.aMapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print(“Error: ” + error.localizedDescription)
}
}
//
// SimpleViewController6.swift
// SimpleViews
//
// Created by Park on 11/21/16.
// Copyright © 2016 Park. All rights reserved.
//
import UIKit
class SimpleViewController6: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var aLabel: UILabel!
@IBOutlet weak var aPickerView: UIPickerView!
enum Activity: String {
case VeryLow = “Very Low”
case Low = “Low”
case Medium = “Medium”
case High = “High”
case VeryHigh = “Very High”
}
let aPickerElements = [“Very Low”, “Low”, “Medium”, “High”, “VeryHigh”]
var activity: Activity = Activity.VeryLow
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.title = “UIPickerView”
// connect picker delegate & dataSource
aPickerView.delegate = self
aPickerView.dataSource = self
// set the default value of picker
aPickerView.selectRow(1, inComponent: 0, animated: true) // Low
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// the number of columns in picker elements
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
// the number of rows in picker elements
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return aPickerElements.count
}
// the element to return for row and column that’s being passed in
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return aPickerElements[row]
}
// when selected UIPickerView row, call this delegate
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch row {
case 0:
activity = Activity.VeryLow
case 1:
activity = Activity.Low
case 2:
activity = Activity.Medium
case 3:
activity = Activity.High
case 4:
activity = Activity.VeryHigh
default:
break
}
aLabel.text = activity.rawValue
}
}