2018년 11월 22일 목요일

ScrollView의 컨텐츠에따라 동적으로 늘어나면서, 불필요할때는 안보이도록


<조건>
1.  스크롤뷰 안의 컨텐츠는 [답변영역]과 [문의영역]으로 나뉘어져있고, 각각의 영역은 Label 사이즈에 따라 자동으로 늘어난다.  
2. 답변이없는 경우에는 [답변영역]이 사라지고, [문의영역]이 위로 올라간다


                      





<솔루션>
1. 스크롤뷰에서 컨텐츠의 높이에 따라 컨테이너뷰들이 자동으로 늘어날 수 있도록 Constraints를 지정한다.




2. Source 코드에서 [답변영역]의 height constraint를 0으로하여 constraint를 추가한다.

override func viewDidLoad() {
        super.viewDidLoad()

        ...
        
        if questionItem?.status != "완료" {
            answerContainerView.heightAnchor.constraint(equalToConstant: 0).isActive = true
        }
    }


2018년 11월 18일 일요일

Two UIViews 사이, 및 앞, 뒤의 공백을 화면사이즈를 따라 Flexible하게 (두 뷰는 고정된사이즈) 하는 방법


두 뷰 사이의 공간 및  leading, tailing 공간이 화면사이즈에따라 늘어나고, 두 뷰는 고정된 사이즈를 유지하는 방법  :

<- flexible -> [view] <- flexible -> [view] <- flexible ->


1.  IB에서 레이아웃만 잡아주는것으로도 가능 함.





여기에서 핵심은  space 역활을 하는 뷰들을 같은 사이즈로 한다는것임.



2018년 11월 7일 수요일

Rounded Corner View

// define

extension UIView {
    func roundCorners(corners:UIRectCorner, radius: CGFloat) {
        DispatchQueue.main.async {
            let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
            let mask = CAShapeLayer()
            mask.path = path.cgPath
            self.layer.mask = mask
        }

    }
}





// using


bubbleView.roundCorners(corners: [.topLeft, .bottomRight, .topRight], radius: 21)




https://www.appcoda.com/bezier-paths-introduction/

2018년 10월 30일 화요일

xcode 버젼 스위칭


현재 xcode 버젼 보기

xcode-select --print-path



스위칭하기

sudo xcode-select --switch /Applications/Xcode9.app/Contents/Developer

2018년 10월 23일 화요일

Fork 을 Original repo 와 동기화 방법

명령어 :

git pull UrlOfOriginalRepo YourCloneRepo


example)

AD01224046:~ user$ git pull https://git-dev.linecorp.com/buffett/client-ios.git develop


2018년 10월 8일 월요일

클래스이름 가져오기



let typeFromClass = String(describing: MyView.self)
        let myView = UINib(nibName: typeFromClass, bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
        let typeFromInstance = String(describing: type(of: myView))
        
        print(typeFromClass) // "MyView"

        print(typeFromInstance) // "MyView"




MyView
MyView

생성자에 파라미터 전송하기


2. instantiate from class with parameters

//  MyView

class MyView: UIView {

    var color: UIColor
    
    required init(frame: CGRect, color: UIColor) {
        self.color = color
        super.init(frame: frame)
        
        // do anything after instantiated
        self.backgroundColor = self.color
    }
    
    required init?(coder aDecoder: NSCoder) { // never called
        fatalError("init(coder:) has not been implemented")
    }
    

}


//  ViewController.swift

override func viewDidLoad() {
        ...
        let myView = MyView(frame: CGRect(x: 0, y: 0, width: 100, height: 200), color: UIColor.cyan)
        ...
    }