Skip to content

Commit

Permalink
Merge pull request #45 from yangsubinn/feature/#40
Browse files Browse the repository at this point in the history
[Feat] #40 - 방생성 설정 뷰 구현
  • Loading branch information
yangsubinn authored Jan 14, 2022
2 parents 0683dba + 72ed1b2 commit ae51433
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
2B947204278CB00E005484C5 /* Futura Medium Italic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2B947201278CB00E005484C5 /* Futura Medium Italic.otf */; };
2B947205278CB00E005484C5 /* Futura Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2B947202278CB00E005484C5 /* Futura Bold.otf */; };
2B9851FD278FCBF400CE40A7 /* UILabel+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B9851FC278FCBF400CE40A7 /* UILabel+.swift */; };
2B9852032790310800CE40A7 /* CreateRoom.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B9852022790310800CE40A7 /* CreateRoom.storyboard */; };
2B985205279031D000CE40A7 /* CreateRoomVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B985204279031D000CE40A7 /* CreateRoomVC.swift */; };
2B9852072790984C00CE40A7 /* UIViewController+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B9852062790984C00CE40A7 /* UIViewController+.swift */; };
2BC1726D278E8F1000BA3029 /* UIView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC1726C278E8F1000BA3029 /* UIView+.swift */; };
2BC17270278F54DB00BA3029 /* WaitingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC1726F278F54DB00BA3029 /* WaitingVC.swift */; };
Expand Down Expand Up @@ -81,6 +83,8 @@
2B947201278CB00E005484C5 /* Futura Medium Italic.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Futura Medium Italic.otf"; sourceTree = "<group>"; };
2B947202278CB00E005484C5 /* Futura Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Futura Bold.otf"; sourceTree = "<group>"; };
2B9851FC278FCBF400CE40A7 /* UILabel+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+.swift"; sourceTree = "<group>"; };
2B9852022790310800CE40A7 /* CreateRoom.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CreateRoom.storyboard; sourceTree = "<group>"; };
2B985204279031D000CE40A7 /* CreateRoomVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateRoomVC.swift; sourceTree = "<group>"; };
2B9852062790984C00CE40A7 /* UIViewController+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+.swift"; sourceTree = "<group>"; };
2BC1726C278E8F1000BA3029 /* UIView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+.swift"; sourceTree = "<group>"; };
2BC1726F278F54DB00BA3029 /* WaitingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitingVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +157,22 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
2B9851FE27902F2B00CE40A7 /* Create */ = {
isa = PBXGroup;
children = (
2B985204279031D000CE40A7 /* CreateRoomVC.swift */,
);
path = Create;
sourceTree = "<group>";
};
2B98520127902F8900CE40A7 /* Create */ = {
isa = PBXGroup;
children = (
2B9852022790310800CE40A7 /* CreateRoom.storyboard */,
);
path = Create;
sourceTree = "<group>";
};
2BC1726E278F54B300BA3029 /* Waiting */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -352,6 +372,7 @@
F80A3E59278C239F00728E07 /* TabBar */,
EB625E97278F8ED200C43DE9 /* StorageMore */,
2BC17272278F56BA00BA3029 /* Waiting */,
2B98520127902F8900CE40A7 /* Create */,
);
path = Storyboards;
sourceTree = "<group>";
Expand All @@ -378,6 +399,7 @@
F82B2E10278F54C200219628 /* Splash */,
F816F123278E1C800008ED00 /* Login */,
2BC1726E278F54B300BA3029 /* Waiting */,
2B9851FE27902F2B00CE40A7 /* Create */,
F80A3E58278C22BA00728E07 /* TabBar */,
EB625E8B278F8D5400C43DE9 /* StorageMore */,
);
Expand Down Expand Up @@ -573,6 +595,7 @@
F80A3E51278C1BCE00728E07 /* Feed.storyboard in Resources */,
F8FAA9772790346000C4190F /* HomeWaitingCVC.xib in Resources */,
2B947203278CB00E005484C5 /* Futura Medium.otf in Resources */,
2B9852032790310800CE40A7 /* CreateRoom.storyboard in Resources */,
F80A3E53278C1C0C00728E07 /* Storage.storyboard in Resources */,
EB625E7C278F271400C43DE9 /* DoingStorageCVC.xib in Resources */,
F8096F0D2784107E00B71D38 /* Assets.xcassets in Resources */,
Expand Down Expand Up @@ -640,6 +663,7 @@
EB625E91278F8E3700C43DE9 /* StorageMoreVC.swift in Sources */,
F8096F3227841FE100B71D38 /* ViewController.swift in Sources */,
F8096F042784107D00B71D38 /* AppDelegate.swift in Sources */,
2B985205279031D000CE40A7 /* CreateRoomVC.swift in Sources */,
2B69E7E5278E22F4000F927F /* FeedHeaderView.swift in Sources */,
F80A3E55278C1C1F00728E07 /* StorageVC.swift in Sources */,
F8096F3A2784210A00B71D38 /* TempModel.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Spark-iOS/Spark-iOS/Resource/Constants/Storyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension Const {
static let login = "Login"
static let splash = "Splash"
static let waiting = "Waiting"
static let createroom = "CreateRoom"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension Const {
static let login = "LoginVC"
static let splash = "SplashVC"
static let waiting = "WaitingVC"
static let createroom = "CreateRoomVC"
}
}
}
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>
3 changes: 2 additions & 1 deletion Spark-iOS/Spark-iOS/Source/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
let rootViewController = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar)
// let rootViewController = UIStoryboard(name: Const.Storyboard.Name.mainTabBar, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.mainTabBar)
let rootViewController = UIStoryboard(name: Const.Storyboard.Name.createroom, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.createroom)
window?.rootViewController = rootViewController

// 코드베이스로 테스트할 때 다음과 같이 사용 가능합니다.
Expand Down
191 changes: 191 additions & 0 deletions Spark-iOS/Spark-iOS/Source/ViewControllers/Create/CreateRoomVC.swift
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()
}
}

}

0 comments on commit ae51433

Please sign in to comment.