-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #40 - 방생성 설정 뷰 구현
- Loading branch information
Showing
6 changed files
with
251 additions
and
1 deletion.
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
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
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
32 changes: 32 additions & 0 deletions
32
Spark-iOS/Spark-iOS/Resource/Storyboards/Create/CreateRoom.storyboard
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,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
<device id="retina6_1" orientation="portrait" appearance="light"/> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19144"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="System colors in document resources" minToolsVersion="11.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--CreateRoomVC--> | ||
<scene sceneID="s0d-6b-0kx"> | ||
<objects> | ||
<viewController storyboardIdentifier="CreateRoomVC" title="CreateRoomVC" id="Y6W-OH-hqX" customClass="CreateRoomVC" customModule="Spark_iOS" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc"> | ||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/> | ||
<color key="backgroundColor" systemColor="systemBackgroundColor"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="-25" y="131"/> | ||
</scene> | ||
</scenes> | ||
<resources> | ||
<systemColor name="systemBackgroundColor"> | ||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
</systemColor> | ||
</resources> | ||
</document> |
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
191 changes: 191 additions & 0 deletions
191
Spark-iOS/Spark-iOS/Source/ViewControllers/Create/CreateRoomVC.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,191 @@ | ||
// | ||
// CreateRoomVC.swift | ||
// Spark-iOS | ||
// | ||
// Created by 양수빈 on 2022/01/13. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
|
||
class CreateRoomVC: UIViewController { | ||
|
||
// MARK: - Properties | ||
|
||
let titleLabel = UILabel() | ||
let subTitleLabel = UILabel() | ||
let textField = UITextField() | ||
let lineView = UIView() | ||
let countLabel = UILabel() | ||
let nextButton = UIButton() | ||
|
||
var maxLength: Int = 15 | ||
|
||
// MARK: - View Life Cycles | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
setUI() | ||
setLayout() | ||
setNotification() | ||
setAddTarget() | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
private func setUI() { | ||
titleLabel.text = "어떤 습관방을 만들건가요?" | ||
titleLabel.font = .h2Title | ||
titleLabel.textColor = .sparkBlack | ||
|
||
subTitleLabel.text = "진행할 습관을 담아 방 이름을 \n설정해보세요!" | ||
subTitleLabel.numberOfLines = 2 | ||
subTitleLabel.font = .krRegularFont(ofSize: 18) | ||
subTitleLabel.textColor = .sparkDarkGray | ||
|
||
nextButton.layer.cornerRadius = 2 | ||
nextButton.titleLabel?.font = .enBoldFont(ofSize: 18) | ||
nextButton.setTitle("다음", for: .normal) | ||
nextButton.backgroundColor = .sparkGray | ||
nextButton.isEnabled = false | ||
|
||
textField.borderStyle = .none | ||
textField.placeholder = "30분 독서" | ||
textField.delegate = self | ||
|
||
lineView.backgroundColor = .sparkGray | ||
|
||
countLabel.text = "0/15" | ||
countLabel.font = .p2SubtitleEng | ||
countLabel.textColor = .sparkDarkGray | ||
} | ||
|
||
private func setLayout() { | ||
view.addSubviews([titleLabel, subTitleLabel, textField, | ||
lineView, countLabel, nextButton]) | ||
|
||
titleLabel.snp.makeConstraints { make in | ||
make.top.equalTo(view.safeAreaLayoutGuide).inset(12) | ||
make.leading.equalToSuperview().inset(20) | ||
} | ||
|
||
subTitleLabel.snp.makeConstraints { make in | ||
make.top.equalTo(titleLabel.snp.bottom).offset(12) | ||
make.leading.equalToSuperview().inset(20) | ||
} | ||
|
||
textField.snp.makeConstraints { make in | ||
make.top.equalTo(subTitleLabel.snp.bottom).offset(96) | ||
make.leading.equalToSuperview().inset(20) | ||
make.width.equalTo(290) | ||
make.height.equalTo(46) | ||
} | ||
|
||
countLabel.snp.makeConstraints { make in | ||
make.centerY.equalTo(textField.snp.centerY) | ||
make.trailing.equalToSuperview().inset(28) | ||
} | ||
|
||
lineView.snp.makeConstraints { make in | ||
make.leading.trailing.equalToSuperview().inset(20) | ||
make.top.equalTo(textField.snp.bottom) | ||
make.height.equalTo(2) | ||
} | ||
|
||
nextButton.snp.makeConstraints { make in | ||
make.leading.trailing.equalToSuperview().inset(20) | ||
make.bottom.equalTo(view.safeAreaLayoutGuide).inset(10) | ||
make.width.equalToSuperview().inset(20) | ||
make.height.equalTo(self.view.frame.width*48/335) | ||
} | ||
} | ||
|
||
private func setNotification() { | ||
NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChange(_:)), name: UITextField.textDidChangeNotification, object: nil) | ||
} | ||
|
||
private func setAddTarget() { | ||
nextButton.addTarget(self, action: #selector(touchNextButton), for: .touchUpInside) | ||
} | ||
|
||
private func ableButton() { | ||
lineView.backgroundColor = .sparkPinkred | ||
nextButton.backgroundColor = .sparkPinkred | ||
nextButton.isEnabled = true | ||
} | ||
|
||
private func disableButton() { | ||
lineView.backgroundColor = .sparkGray | ||
nextButton.backgroundColor = .sparkGray | ||
nextButton.isEnabled = false | ||
} | ||
|
||
@objc | ||
private func textFieldDidChange(_ notification: Notification) { | ||
if let textField = notification.object as? UITextField { | ||
if let text = textField.text { | ||
/// 글자가 바뀔 때마다 countLabel 업데이트 | ||
countLabel.text = "\(text.count)/15" | ||
|
||
/// 글자수 count 초과한 경우 | ||
if text.count >= maxLength { | ||
let maxIndex = text.index(text.startIndex, offsetBy: maxLength) | ||
let newString = String(text[text.startIndex..<maxIndex]) | ||
textField.text = newString | ||
countLabel.text = "15/15" | ||
countLabel.textColor = .sparkPinkred | ||
} | ||
|
||
/// 글자 있는 경우 색 활성화, 없는 경우 비활성화 | ||
else if text.count > 0 { | ||
let attributedString = NSMutableAttributedString(string: countLabel.text ?? "") | ||
attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.sparkPinkred, range: ((countLabel.text ?? "") as NSString).range(of:"\(text.count)")) | ||
countLabel.textColor = .sparkDarkGray | ||
countLabel.attributedText = attributedString | ||
} | ||
|
||
/// 그 외 0인 경우 | ||
else { | ||
countLabel.textColor = .sparkDarkGray | ||
} | ||
} | ||
} | ||
} | ||
|
||
@objc | ||
func touchNextButton() { | ||
// TODO: - 화면전환 | ||
print("다음") | ||
} | ||
} | ||
|
||
extension CreateRoomVC: UITextFieldDelegate { | ||
/// 여백 클릭 시 | ||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ | ||
self.view.endEditing(true) | ||
} | ||
|
||
/// 리턴 눌렀을 때 | ||
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | ||
self.view.endEditing(true) | ||
return true | ||
} | ||
|
||
/// 입력 시작 | ||
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { | ||
ableButton() | ||
return true | ||
} | ||
|
||
/// 입력 끝 | ||
func textFieldDidEndEditing(_ textField: UITextField) { | ||
if textField.hasText { | ||
ableButton() | ||
} else { | ||
disableButton() | ||
} | ||
} | ||
|
||
} |