-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from naneun/chez-search#6
[iOS] 검색바를 터치하면 검색용 화면으로 이동할 수 있음 #6
- Loading branch information
Showing
5 changed files
with
164 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// PlaceCollectionViewCell.swift | ||
// Cherrybnb | ||
// | ||
// Created by 최예주 on 2022/05/25. | ||
// Copyright © 2022 Codesquad. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class PlaceCell: UICollectionViewCell { | ||
private var imageView = UIImageView() | ||
private var nameLabel = UILabel() | ||
private var distanceLabel = UILabel() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setComponents() | ||
setLayout() | ||
} | ||
|
||
required init?(coder: NSCoder){ | ||
super.init(coder: coder) | ||
} | ||
|
||
func setComponents(){ | ||
setImageView() | ||
setNameLabel() | ||
setDistanceLabel() | ||
} | ||
|
||
func setImageView(){ | ||
self.contentView.addSubview(imageView) | ||
imageView.image = UIImage(named: "Place_thumb_1") | ||
imageView.layer.cornerRadius = 10 | ||
} | ||
|
||
func setNameLabel(){ | ||
self.contentView.addSubview(nameLabel) | ||
nameLabel.font = .systemFont(ofSize: 17) | ||
nameLabel.text = "서울" | ||
} | ||
|
||
func setDistanceLabel(){ | ||
self.contentView.addSubview(distanceLabel) | ||
distanceLabel.font = .systemFont(ofSize: 17) | ||
distanceLabel.textColor = .systemGray | ||
distanceLabel.text = "차로 30분 거리" | ||
} | ||
|
||
func setLayout(){ | ||
imageView.translatesAutoresizingMaskIntoConstraints = false | ||
imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true | ||
imageView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true | ||
imageView.widthAnchor.constraint(equalToConstant: 64).isActive = true | ||
imageView.heightAnchor.constraint(equalToConstant: 64).isActive = true | ||
imageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true | ||
|
||
nameLabel.translatesAutoresizingMaskIntoConstraints = false | ||
nameLabel.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 16).isActive = true | ||
nameLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8).isActive = true | ||
nameLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true | ||
nameLabel.heightAnchor.constraint(equalToConstant: 22).isActive = true | ||
|
||
distanceLabel.translatesAutoresizingMaskIntoConstraints = false | ||
distanceLabel.leadingAnchor.constraint(equalTo: nameLabel.leadingAnchor).isActive = true | ||
distanceLabel.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 4).isActive = true | ||
distanceLabel.heightAnchor.constraint(equalToConstant: 22).isActive = true | ||
distanceLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16).isActive = true | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
iOS/Targets/Cherrybnb/Sources/Search/ViewController/ListCollectionViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// ListCollectionViewController.swift | ||
// Cherrybnb | ||
// | ||
// Created by 최예주 on 2022/05/25. | ||
// Copyright © 2022 Codesquad. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class ListCollectionViewController: UIViewController { | ||
|
||
private var collectionView: UICollectionView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
setCollectionView() | ||
setLayout() | ||
self.navigationItem.title = "숙소찾기" | ||
} | ||
|
||
private func setCollectionView(){ | ||
let layout = UICollectionViewFlowLayout() | ||
layout.scrollDirection = .vertical | ||
collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height), collectionViewLayout: layout) | ||
self.view.addSubview(collectionView) | ||
|
||
collectionView.delegate = self | ||
collectionView.dataSource = self | ||
|
||
collectionView.register(PlaceCell.self, forCellWithReuseIdentifier: "placeCell") | ||
} | ||
|
||
private func setLayout(){ | ||
collectionView.translatesAutoresizingMaskIntoConstraints = false | ||
collectionView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true | ||
collectionView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true | ||
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | ||
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true | ||
} | ||
} | ||
|
||
extension ListCollectionViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | ||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return 3 | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
|
||
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "placeCell", for: indexPath) as? PlaceCell else { return UICollectionViewCell() } | ||
return cell | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
let size = CGSize(width: self.view.frame.width, height: 64) | ||
return size | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters