Skip to content

Instantly share code, notes, and snippets.

@kbw2204
kbw2204 / UICollecionViewController.swift
Last active August 17, 2020 13:11
UICollecionViewController
// UICollecionViewController
class UICollectionViewController : UIViewController
@kbw2204
kbw2204 / UICollectionView.swift
Created August 17, 2020 13:13
UICollectionView 정의
// collectionView
class UICollectionView : UIScrollView
@kbw2204
kbw2204 / collectionViewHeader 고정.swift
Last active August 18, 2020 09:33
collectionViewHeader를 고정시키고 싶을 때 사용하는 설정값입니다.
// MARK: flowLayout
let flowLayout = UICollectionViewFlowLayout()
flowLayout.sectionHeadersPinToVisibleBounds = true
extension ViewController: UICollectionViewDataSource {
// MARK: cell count
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return palette.count
}
// MARK: cell
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell: CustomCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "\(CustomCollectionViewCell.self)", for: indexPath) as? CustomCollectionViewCell else {
return UICollectionViewCell()
extension ViewController: UICollectionViewDelegate {
// MARK: selected
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("\(indexPath.item)번 Cell 클릭")
}
}
extension ViewController: UICollectionViewDelegateFlowLayout {
// MARK: cellSize
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let collectionViewWidth = collectionView.bounds.width
let cellItemForRow: CGFloat = 3
let minimumSpacing: CGFloat = 2
let width = (collectionViewWidth - (cellItemForRow - 1) * minimumSpacing) / cellItemForRow
return CGSize(width: width, height: width)
import UIKit
class CustomCollectionViewCell: UICollectionViewCell {
weak var imageView: UIImageView?
override init(frame: CGRect) {
super.init(frame: frame)
let imageView = UIImageView()
self.imageView = imageView
import UIKit
class ViewController: UIViewController {
// MARK: - Property
let palette: [UIColor] = [.red, .orange, .yellow, .green, .blue]
// MARK: - View
private var collectionView: UICollectionView?
@kbw2204
kbw2204 / set presentStyle.swift
Last active August 27, 2020 08:14
set presentStyle.swift
let nextviewController = SecondViewController()
nextviewController.modalPresentationStyle = .fullScreen
nextviewController.modalTransitionStyle = .partialCurl
present(nextviewController, animated: true)
Observable.just(data) // Observable을 만들어 주고
.bind(to: tableView.rx.items()) // tableView.rx.items()를 바인딩 해주고
.disposed(by: disposeBag) // disposeBag에 넣어주면 됩니다.