페이지

2020년 3월 11일 수요일

Change navigation back button image



override func viewDidLoad() {
    super.viewDidLoad()
    let backBtn = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    backBtn.setBackButtonBackgroundImage(UIImage(named:"myBackButton"), for: .normal, barMetrics: .default)
    navigationItem.backBarButtonItem = backBtn
    navigationController?.navigationBar.backIndicatorImage = UIImage()
    navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage()

}

2020년 3월 10일 화요일

UINavigationBar Height change


class MyNavigationController : UINavigationController {
    override func viewDidLoad(){
        super.viewDidLoad()
        self.additionalSafeAreaInsets.top = 70 // not including statusBar (44pt), navigationBar (44pt)    
    }
}



2020년 3월 6일 금요일

push vs present



class ViewController:UIViewController {

     ....

     func showPopup(){
            let popupVc = AppDelegate.shared.getVC( "\(PopupViewController.self)")

             // 1. pushViewController
             //self.navigationController?.pushViewController( popupVc,  animated:true)

             // 2. present ViewController

             //self.present( popupVc, animated:true, completion:nil )
     }
}


1. pushViewController

ViewController disappeared. but navigationController manages this ViewController.




2. present ViewController

ViewController didn't disappear.
PopupViewController is stacked on the ViewController.
UIWindow has 2 UITransitionViews ( navigationController , PopupViewController )

2020년 2월 9일 일요일

Swift ?? operator, Characters

// 1. ?? operator
var a : Int?
let c : Int?
var b : Int = 123

var ss = a ?? b
print(ss)
ss = c ?? b // error : constant c is used before being initialized.
print(ss)
a = nil
ss = a ?? b
print(ss)




// 2. Working with Characters
for character in "Dog!^^".characters {
    print(character)
}



let catCharacters: [Character] = ["C","a","t","!"]
let catString = String(catCharacters)
print(catString)

var tmp = catString
tmp.append("?")
print(tmp)


Swift collection: array, set,dictionary

// 1. Collection : Array
var a = [Int]()
var b = Array(repeating: 4, count: 3)
print(a)
print(b)
a = [1,2,3]
var c = a + b
print(c)
c += [5,6]
print(c)

c[2...5] = [9,10]  //it's brilliant way.
print(c)
for (index, val) in c.enumerated(){
    print( "\(index) => \(val)" )
}



// 2. Collection : Set
var even:Set<Int> = [2,4,6,8,10]
var odd:Set = [1,3,5,7,9]
var tmp = Set<Int>()
even.insert(12)
tmp = [2,3,4,5]

print(tmp.intersection(odd))
print(tmp.union(even))
print(tmp.symmetricDifference(even).sorted())























//3. Collection : Dictionary
var dict = [Int:String]()
dict = [:]
print(dict)

var airportCode = ["a":"america", "b":"bangkok", "c":"china"]
for( key, value ) in airportCode {
    print( "key:\(key) val:\(value)")
}




Swift loop, switch,fallthrough

//1. loop

for i in 0...3 {
    print(i)
}

for i in (0...3).reversed(){
    print(i)
}


//2. switch interval matching
let a = 32
switch a {
case 0,3:
    print("0,3")
case 0...19:
    print("...19")
case 20..<40:
    print("20..<40")
default:
    print("default")
}





// switch tuples

let a = (1, 1)
switch a {
case (0, 0):
    print("(0, 0) is at the origin")
case (_, 0):
    print("(\(a.0), 0) is on the x-axis")
case (0, _):
    print("(0, \(a.1)) is on the y-axis")
case (-2...2, -2...2):
    print("(\(a.0), \(a.1)) is inside the box")
default:
    print("(\(a.0), \(a.1)) is outside of the box")

}





// switch value binding

let a = (2, 0)
switch a {
case (let x, 0):
    print("on the x-axis with an x value of \(x)")
case (0, let y):
    print("on the y-axis with a y value of \(y)")
case let (x, y):
    print("somewhere else at (\(x), \(y))")
case (let x,0),(0, let x):       
    //warning: case will never be executed
    print("On an axis, \(x) from the origin")
case (let x,0),(0, let y) :      
    //error: x,y must be bound in every pattern
    print("error")

}





//switch where

let a = (101,10)
switch a {
case let(x,y) where x == y :
    print("x==y")
case let(x,y) where x >= y :
    print("x>=y")
case let(x,y) where x <= y :
    print("x<=y")
default:
    print("default")
}



// switch fallthrough

var a = 1
switch a {
    case 0...4:
        print("0...4")
        fallthrough
    case 5...10:
        print("5....10")
    case 11...14:
        print("11...14")
    default:
        print("default")
}




Light Normal Bias