Skip to content

Commit

Permalink
starting to convert book 2 chapter 8 examples for Xcode 8 seed 6; als…
Browse files Browse the repository at this point in the history
…o, deal globally with color names
  • Loading branch information
mattneub committed Aug 25, 2016
1 parent a8745d7 commit a93fa54
Show file tree
Hide file tree
Showing 66 changed files with 298 additions and 264 deletions.
Expand Up @@ -112,7 +112,7 @@ class ViewController : UIViewController {
var previousLab : UILabel? = nil
for i in 0 ..< 30 {
let lab = UILabel()
// lab.backgroundColor = UIColor.red()
// lab.backgroundColor = .red
lab.translatesAutoresizingMaskIntoConstraints = false
lab.text = "This is label \(i+1)"
v.addSubview(lab) // *
Expand Down Expand Up @@ -164,7 +164,7 @@ class ViewController : UIViewController {
var previousLab : UILabel? = nil
for i in 0 ..< 30 {
let lab = UILabel()
// lab.backgroundColor = UIColor.red()
// lab.backgroundColor = .red
lab.translatesAutoresizingMaskIntoConstraints = false
lab.text = "This is label \(i+1)"
v.addSubview(lab) // *
Expand Down
Expand Up @@ -28,7 +28,7 @@ class ViewController : UIViewController {
var previousLab : UILabel? = nil
for i in 0 ..< 30 {
let lab = UILabel()
// lab.backgroundColor = UIColor.red()
// lab.backgroundColor = .red
lab.translatesAutoresizingMaskIntoConstraints = false
lab.text = "This is label \(i+1)"
sv.addSubview(lab)
Expand Down
Expand Up @@ -39,28 +39,29 @@ class RootViewController : UITableViewController {
if cell == nil {
cell = UITableViewCell(style:.default, reuseIdentifier:cellIdentifier)

cell.textLabel!.textColor = UIColor.white()
cell.textLabel!.textColor = .white

let v = UIImageView() // no need to set frame
v.contentMode = .scaleToFill
v.image = UIImage(named:"linen.png")
cell.backgroundView = v

let v2 = UIView() // no need to set frame
v2.backgroundColor = UIColor.blue().withAlphaComponent(0.2)
v2.backgroundColor = UIColor.blue.withAlphaComponent(0.2)
cell.selectedBackgroundView = v2
// next line no longer necessary in iOS 7!
// cell.textLabel.backgroundColor = UIColor.clear()
// cell.textLabel.backgroundColor = .clear

// next line didn't work until iOS 7!
cell.backgroundColor = UIColor.red()
cell.backgroundColor = .red

// let b = UIButton(type:.System)
// b.setTitle("Tap Me", for:[])
// let b = UIButton(type:.system)
// b.setTitle("Tap Me", for:.normal)
// b.sizeToFit()
// // ... add action and target here ...
// cell.accessoryView = b

// cell.textLabel!.font = UIFont(name:"Helvetica-Bold", size:12.0)
// cell.textLabel!.font = UIFont(name:"Helvetica-Bold", size:12.0)


}
Expand Down
Expand Up @@ -2,7 +2,7 @@

import UIKit

// Not in book: how to get separator to run from edge to edge
// how to get separator to run from edge to edge

class RootViewController: UITableViewController {

Expand All @@ -18,8 +18,10 @@ class RootViewController: UITableViewController {

// must set all three of these:
print(cell.separatorInset)
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
cell.separatorInset = .zero

// NO! they fixed this too
// cell.layoutMargins = .zero

// NO! They fixed this!!!!! No need for this trick any longer
//cell.preservesSuperviewLayoutMargins = false
Expand Down
Expand Up @@ -2,14 +2,15 @@
import UIKit

class MyCell : UITableViewCell {
/*

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style:.Subtitle, reuseIdentifier: reuseIdentifier)
super.init(style:.default, reuseIdentifier: reuseIdentifier)
// change .default to another built-in style if desired
}
required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}
*/
override func layoutSubviews() {
super.layoutSubviews()
let cvb = self.contentView.bounds
Expand Down
Expand Up @@ -50,7 +50,7 @@ class RootViewController : UITableViewController {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:"Cell", for: indexPath)
if cell.viewWithTag(1) == nil {
if cell.viewWithTag(1) == nil { // no subviews! add them
let iv = UIImageView()
iv.tag = 1
cell.contentView.addSubview(iv)
Expand All @@ -59,7 +59,7 @@ class RootViewController : UITableViewController {
lab.tag = 2
cell.contentView.addSubview(lab)

// since we are now adding the views ourselves (not reusing the default views),
// since we are now adding the views ourselves,
// we can use autolayout to lay them out

let d = ["iv":iv, "lab":lab]
Expand Down
Expand Up @@ -40,7 +40,7 @@ class RootViewController: UITableViewController {

// uncomment to show that the refresh control is hidden behind the background view
// let v = UIView()
// v.backgroundColor = UIColor.yellow()
// v.backgroundColor = .yellow
// self.tableView.backgroundView = v
}

Expand Down
20 changes: 10 additions & 10 deletions bk2ch08p416sections/ch21p718sections/RootViewController.swift
Expand Up @@ -11,7 +11,7 @@ class RootViewController : UITableViewController {
}

override func viewDidLoad() {
let s = try! String(contentsOfFile: Bundle.main.pathForResource("states", ofType: "txt")!)
let s = try! String(contentsOfFile: Bundle.main.path(forResource: "states", ofType: "txt")!)
let states = s.components(separatedBy:"\n")
var previous = ""
for aState in states {
Expand All @@ -29,9 +29,9 @@ class RootViewController : UITableViewController {
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
self.tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "Header")

self.tableView.sectionIndexColor = UIColor.white()
self.tableView.sectionIndexBackgroundColor = UIColor.red()
self.tableView.sectionIndexTrackingBackgroundColor = UIColor.blue()
self.tableView.sectionIndexColor = .white
self.tableView.sectionIndexBackgroundColor = .red
self.tableView.sectionIndexTrackingBackgroundColor = .blue
// not useful in this situation
// self.tableView.separatorEffect = UIBlurEffect(style: .Dark)
}
Expand Down Expand Up @@ -68,20 +68,20 @@ class RootViewController : UITableViewController {
// this is more "interesting"
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let h = tableView.dequeueReusableHeaderFooterView(withIdentifier:"Header")!
if h.tintColor != UIColor.red() {
if h.tintColor != .red {
print("configuring a new header view") // only called about 7 times
h.tintColor = UIColor.red() // invisible marker, tee-hee
h.tintColor = .red // invisible marker, tee-hee
h.backgroundView = UIView()
h.backgroundView?.backgroundColor = UIColor.black()
h.backgroundView?.backgroundColor = .black
let lab = UILabel()
lab.tag = 1
lab.font = UIFont(name:"Georgia-Bold", size:22)
lab.textColor = UIColor.green()
lab.backgroundColor = UIColor.clear()
lab.textColor = .green
lab.backgroundColor = .clear
h.contentView.addSubview(lab)
let v = UIImageView()
v.tag = 2
v.backgroundColor = UIColor.black()
v.backgroundColor = .black
v.image = UIImage(named:"us_flag_small.gif")
h.contentView.addSubview(v)
lab.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Expand Up @@ -16,7 +16,7 @@ class RootViewController : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()

let url = Bundle.main.urlForResource("trivia", withExtension: "txt")
let url = Bundle.main.url(forResource:"trivia", withExtension: "txt")
let s = try! String(contentsOf:url!)
var arr = s.components(separatedBy:"\n")
arr.removeLast()
Expand Down
Expand Up @@ -85,16 +85,16 @@ class RootViewController : UITableViewController {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = UIColor.clear()
// v.backgroundColor = UIColor.yellow()
// tableView.backgroundColor = UIColor.green()
v.backgroundColor = .clear
// v.backgroundColor = .yellow
// tableView.backgroundColor = .green
return v
}
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = UIColor.blue()
v.backgroundColor = .blue
return v
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
}

override func viewDidLoad() {
let s = try! String(contentsOfFile: Bundle.main.pathForResource("states", ofType: "txt")!)
let s = try! String(contentsOfFile: Bundle.main.path(forResource: "states", ofType: "txt")!)
let states = s.components(separatedBy:"\n")
var previous = ""
for aState in states {
Expand All @@ -39,13 +39,13 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
self.tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "Header")

self.tableView.sectionIndexColor = UIColor.white()
self.tableView.sectionIndexBackgroundColor = UIColor.red()
// self.tableView.sectionIndexTrackingBackgroundColor = UIColor.blue()
self.tableView.backgroundColor = UIColor.yellow() // but the search bar covers that
self.tableView.sectionIndexColor = .white
self.tableView.sectionIndexBackgroundColor = .red
// self.tableView.sectionIndexTrackingBackgroundColor = .blue
self.tableView.backgroundColor = .yellow // but the search bar covers that
self.tableView.backgroundView = { // this will fix it
let v = UIView()
v.backgroundColor = UIColor.yellow()
v.backgroundColor = .yellow
return v
}()

Expand Down Expand Up @@ -108,19 +108,19 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let h = tableView
.dequeueReusableHeaderFooterView(withIdentifier:"Header")!
if h.tintColor != UIColor.red() {
h.tintColor = UIColor.red() // invisible marker, tee-hee
if h.tintColor != .red {
h.tintColor = .red // invisible marker, tee-hee
h.backgroundView = UIView()
h.backgroundView?.backgroundColor = UIColor.black()
h.backgroundView?.backgroundColor = .black
let lab = UILabel()
lab.tag = 1
lab.font = UIFont(name:"Georgia-Bold", size:22)
lab.textColor = UIColor.green()
lab.backgroundColor = UIColor.clear()
lab.textColor = .green
lab.backgroundColor = .clear
h.contentView.addSubview(lab)
let v = UIImageView()
v.tag = 2
v.backgroundColor = UIColor.black()
v.backgroundColor = .black
v.image = UIImage(named:"us_flag_small.gif")
h.contentView.addSubview(v)
lab.translatesAutoresizingMaskIntoConstraints = false
Expand Down
Expand Up @@ -18,7 +18,7 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
}

override func viewDidLoad() {
let s = try! String(contentsOfFile: Bundle.main.pathForResource("states", ofType: "txt")!)
let s = try! String(contentsOfFile: Bundle.main.path(forResource: "states", ofType: "txt")!)
let states = s.components(separatedBy:"\n")
var previous = ""
for aState in states {
Expand All @@ -36,13 +36,13 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
self.tableView.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "Header")

self.tableView.sectionIndexColor = UIColor.white()
self.tableView.sectionIndexBackgroundColor = UIColor.red()
// self.tableView.sectionIndexTrackingBackgroundColor = UIColor.blue()
// self.tableView.backgroundColor = UIColor.yellow()
self.tableView.sectionIndexColor = .white
self.tableView.sectionIndexBackgroundColor = .red
// self.tableView.sectionIndexTrackingBackgroundColor = .blue
// self.tableView.backgroundColor = .yellow
self.tableView.backgroundView = {
let v = UIView()
v.backgroundColor = UIColor.yellow()
v.backgroundColor = .yellow
return v
}()

Expand Down Expand Up @@ -89,19 +89,19 @@ class RootViewController : UITableViewController, UISearchBarDelegate {
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let h = tableView
.dequeueReusableHeaderFooterView(withIdentifier:"Header")!
if h.tintColor != UIColor.red() {
h.tintColor = UIColor.red() // invisible marker, tee-hee
if h.tintColor != .red {
h.tintColor = .red // invisible marker, tee-hee
h.backgroundView = UIView()
h.backgroundView?.backgroundColor = UIColor.black()
h.backgroundView?.backgroundColor = .black
let lab = UILabel()
lab.tag = 1
lab.font = UIFont(name:"Georgia-Bold", size:22)
lab.textColor = UIColor.green()
lab.backgroundColor = UIColor.clear()
lab.textColor = .green
lab.backgroundColor = .clear
h.contentView.addSubview(lab)
let v = UIImageView()
v.tag = 2
v.backgroundColor = UIColor.black()
v.backgroundColor = .black
v.image = UIImage(named:"us_flag_small.gif")
h.contentView.addSubview(v)
lab.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -160,19 +160,19 @@ extension RootViewController : UISearchControllerDelegate, UIViewControllerTrans
return self
}

func animationController(forDismissedController dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}

func transitionDuration(_ transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.3
}

func animateTransition(_ transitionContext: UIViewControllerContextTransitioning) {
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let vc1 = transitionContext.viewController(forKey:.from)!
let vc2 = transitionContext.viewController(forKey:.to)!

let con = transitionContext.containerView()
let con = transitionContext.containerView

// let r1start = transitionContext.initialFrame(for:vc1)
let r2end = transitionContext.finalFrame(for:vc2)
Expand Down
Expand Up @@ -48,7 +48,7 @@ extension SearchResultsController : UISearchResultsUpdating {
var options = String.CompareOptions.caseInsensitive
// we now have scope buttons; 0 means "starts with"
if searchController.searchBar.selectedScopeButtonIndex == 0 {
_ = options.insert(.anchoredSearch) // bug?
_ = options.insert(.anchored) // bug?
}
let found = s.range(of:target, options: options)
return (found != nil)
Expand Down

0 comments on commit a93fa54

Please sign in to comment.