swift] protocol 사용 Delegate 만들어서 사용해보기!
UploadPostController.swift에서 프로토콜을 선언해주고 해당 프로토콜을 상속받는 delegate라는 변수를 만들어준다. 이제 해당 delegate를 사용할 곳에서 이렇게 선언을 해주고 이 delegate를 처리할 다른 뷰 컨트롤러에서 이렇게 extension을 사용하여 해당 프로토콜을 상속받고 프로토콜에 전달된 함수를 구현하여 기능을 처리한다.
UploadPostController.swift에서 프로토콜을 선언해주고 해당 프로토콜을 상속받는 delegate라는 변수를 만들어준다. 이제 해당 delegate를 사용할 곳에서 이렇게 선언을 해주고 이 delegate를 처리할 다른 뷰 컨트롤러에서 이렇게 extension을 사용하여 해당 프로토콜을 상속받고 프로토콜에 전달된 함수를 구현하여 기능을 처리한다.
navigationController?.navigationBar.barStyle = .black barStyle을 블랙으로주면 아래처럼 바뀐다. 색상은 default와 블랙 두 가지이다.
let gradient = CAGradientLayer() gradient.colors = [UIColor.systemPurple.cgColor, UIColor.systemBlue.cgColor] gradient.locations = [0,1] view.layer.addSublayer(gradient) gradient.frame = view.frame gradient.locations = [0,1]의 숫자를 [0],[0.5]...[1] 이런식으로 변경하면 그라데이션의 효과를 다르게 줄 수 있다.
-View - FeedCell.swift import UIKit class FeedCell: UICollectionViewCell{ //MARK: - Propertie //MARK: - Lifecycle override init(frame: CGRect){ super.init(frame: frame) backgroundColor = .brown } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } //MARK: - API //MARK: - Actions //MARK: - Helpers } -Controller - FeedController class FeedController: UICollection..
class FeedController: UICollectionViewController- UITabBarController에 선언되어있는 FeedController은 UICollectionViewController이다 이 상태로 런을 하면 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'같은 에러가 나타난다 UICollectionView는 Nil이 아닌 레이아웃 매개 변수로 초기화해야 하기때문. let layout = UICollectionViewFlowLayout() let feed = templateNavigationController(unselectedIm..
우선 각 각의 컨트롤러는 import UIKit class SearchController: UIViewController{ override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .yellow } } 이런식으로 백그라운드 색상만 설정은 해놨다. 그리고 UITabBarController을 상속받은 MainTabController에서 templateNavigationController함수를 만들어 각 각의 뷰컨트롤러를 네비게이션컨트롤러로 선언을 해주고 unselectedImage와 selectedImage를 설정을 해줬다. func configureViewControllers(){ view.backgroundColor = .white..