【Swift】storyboard를 이용하지 않는 템플릿(UICollectionView, UICollectionViewCell)

개요



PureLayout의 샘플(UICollectionView, UICollectionViewCell) 제3탄입니다.
Yahoo 경매 검색 API 결과가 CollectionView에 표시됩니다.
다음에는 UITabBar

목적



storyboard를 사용하지 않는 최소한의 템플릿(Swift)을 참조하십시오.

장점 (PureLayout vs Storyboard)



[Swift] storyboard를 사용하지 않는 템플릿(기본 View)을 참조하십시오.

대상View


  • UICollectionView
  • UICollectionViewCell

  • 결과



    サンプル

    github


  • htps : // 기주 b. 코 m/메노모토/사 mpぇ_뿌레아 t/t레에/마s테r
  • xcode8, swift2.3
  • iPhone5,6,6s UI 확인 OK

  • AutoLayout 설정



    CollectionView(&SearchBar)


        private func addConstraints() {
            searchBar.autoPinToTopLayoutGuideOfViewController(self, withInset: 0)
            searchBar.autoPinEdgeToSuperviewEdge(.Left)
            searchBar.autoPinEdgeToSuperviewEdge(.Right)
    
            collectionView.autoPinEdge(.Top, toEdge: .Bottom, ofView: searchBar)
            collectionView.autoPinEdgeToSuperviewEdge(.Left)
            collectionView.autoPinEdgeToSuperviewEdge(.Right)
            collectionView.autoPinEdgeToSuperviewEdge(.Bottom)
        }
    

    CollectionViewCell의 각 View


        private func addConstraints() {
            itemImageView.autoPinEdgeToSuperviewEdge(.Top, withInset: 2)
            itemImageView.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
            itemImageView.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
    
            titleLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: itemImageView, withOffset: 3.0)
            titleLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
            titleLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
    
            priceLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 3.0)
            priceLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
            priceLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
    
            endTimeLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
            endTimeLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
            endTimeLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
    
            bidLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
            bidLabel.autoPinEdge(.Left, toEdge: .Right, ofView: endTimeLabel, withOffset: 10.0)
            bidLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
    
        }
    

    좋은 웹페이지 즐겨찾기