Skip to content

Commit

Permalink
SeSAC 2주 1일차 (230724 .Mon)
Browse files Browse the repository at this point in the history
1. AutoLayout으로 제약조건 설정하기
2. keyboard 내리기 -> return key / gesture tap
3. 컬러 버튼 클릭 시 -> textLabel Color 랜덤하게 변경하기
4. 비어있는 뷰 클릭 시 -> 상단뷰(topView) isHidden 값 처리하기 (수업시간에 배운 4가지의 방법 참고)
  • Loading branch information
RaeBaek committed Jul 24, 2023
1 parent 7fac065 commit 5ebc1f9
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 6 deletions.
8 changes: 8 additions & 0 deletions LEDBoard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
143AEAF42A6E6FE100D7B162 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 143AEAF22A6E6FE100D7B162 /* Main.storyboard */; };
143AEAF62A6E6FE300D7B162 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 143AEAF52A6E6FE300D7B162 /* Assets.xcassets */; };
143AEAF92A6E6FE300D7B162 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 143AEAF72A6E6FE300D7B162 /* LaunchScreen.storyboard */; };
143AEB012A6E742C00D7B162 /* BoardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 143AEB002A6E742C00D7B162 /* BoardViewController.swift */; };
143AEB032A6E77E400D7B162 /* UITextField+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 143AEB022A6E77E400D7B162 /* UITextField+.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -24,6 +26,8 @@
143AEAF52A6E6FE300D7B162 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
143AEAF82A6E6FE300D7B162 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
143AEAFA2A6E6FE300D7B162 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
143AEB002A6E742C00D7B162 /* BoardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoardViewController.swift; sourceTree = "<group>"; };
143AEB022A6E77E400D7B162 /* UITextField+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -59,6 +63,8 @@
143AEAEC2A6E6FE100D7B162 /* AppDelegate.swift */,
143AEAEE2A6E6FE100D7B162 /* SceneDelegate.swift */,
143AEAF02A6E6FE100D7B162 /* ViewController.swift */,
143AEB002A6E742C00D7B162 /* BoardViewController.swift */,
143AEB022A6E77E400D7B162 /* UITextField+.swift */,
143AEAF22A6E6FE100D7B162 /* Main.storyboard */,
143AEAF52A6E6FE300D7B162 /* Assets.xcassets */,
143AEAF72A6E6FE300D7B162 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -139,8 +145,10 @@
buildActionMask = 2147483647;
files = (
143AEAF12A6E6FE100D7B162 /* ViewController.swift in Sources */,
143AEB032A6E77E400D7B162 /* UITextField+.swift in Sources */,
143AEAED2A6E6FE100D7B162 /* AppDelegate.swift in Sources */,
143AEAEF2A6E6FE100D7B162 /* SceneDelegate.swift in Sources */,
143AEB012A6E742C00D7B162 /* BoardViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file modified LEDBoard/._AppDelegate.swift
Binary file not shown.
Binary file modified LEDBoard/._ViewController.swift
Binary file not shown.
Binary file modified LEDBoard/Base.lproj/._Main.storyboard
Binary file not shown.
95 changes: 89 additions & 6 deletions LEDBoard/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,24 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<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>
<!--View Controller-->
<!--Board View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="BoardViewController" customModule="LEDBoard" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="DAf-P6-gxo">
<rect key="frame" x="16" y="75" width="361" height="60"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="t0w-LP-RY2">
<rect key="frame" x="0.0" y="0.0" width="216.66666666666666" height="60"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
<action selector="keyboardReturnKeyTapped:" destination="BYZ-38-t0r" eventType="editingDidEndOnExit" id="Qxa-RQ-xlj"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="D5u-KK-Hm1">
<rect key="frame" x="271" y="12.666666666666671" width="35" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="B"/>
<connections>
<action selector="sendButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="zCT-bT-Znx"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4Fj-lC-uWo">
<rect key="frame" x="316" y="12.666666666666671" width="35" height="35"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="B"/>
<connections>
<action selector="setRandomColor:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Mtc-fu-TAn"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="t0w-LP-RY2" firstAttribute="top" secondItem="DAf-P6-gxo" secondAttribute="top" id="1mB-Sh-rys"/>
<constraint firstItem="4Fj-lC-uWo" firstAttribute="centerY" secondItem="DAf-P6-gxo" secondAttribute="centerY" id="8PM-4s-hMJ"/>
<constraint firstItem="4Fj-lC-uWo" firstAttribute="leading" secondItem="D5u-KK-Hm1" secondAttribute="trailing" constant="10" id="S7T-lF-tu2"/>
<constraint firstItem="t0w-LP-RY2" firstAttribute="width" secondItem="DAf-P6-gxo" secondAttribute="width" multiplier="0.6" id="Wrs-cA-oyD"/>
<constraint firstItem="D5u-KK-Hm1" firstAttribute="centerY" secondItem="DAf-P6-gxo" secondAttribute="centerY" id="eQx-jm-o9l"/>
<constraint firstAttribute="height" constant="60" id="kY5-Ur-n50"/>
<constraint firstAttribute="trailing" secondItem="4Fj-lC-uWo" secondAttribute="trailing" constant="10" id="mpe-jg-MOi"/>
<constraint firstAttribute="bottom" secondItem="t0w-LP-RY2" secondAttribute="bottom" id="qTC-Fl-zEX"/>
<constraint firstItem="t0w-LP-RY2" firstAttribute="leading" secondItem="DAf-P6-gxo" secondAttribute="leading" id="sdk-LH-9c8"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="원하는 내용을 입력할 수 있고 글자색도 바꿀 수 있습니다." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="T7G-7J-t6N">
<rect key="frame" x="20" y="155" width="353" height="643"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="T7G-7J-t6N" secondAttribute="trailing" constant="20" id="HdE-ts-LEW"/>
<constraint firstItem="T7G-7J-t6N" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="Kql-Lp-Pxp"/>
<constraint firstItem="T7G-7J-t6N" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="NVy-CC-8wo"/>
<constraint firstItem="DAf-P6-gxo" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="X8p-5q-fU4"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="T7G-7J-t6N" secondAttribute="bottom" constant="20" id="nEb-TO-6Zr"/>
<constraint firstItem="DAf-P6-gxo" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="16" id="ogc-t8-YVO"/>
<constraint firstItem="T7G-7J-t6N" firstAttribute="top" secondItem="DAf-P6-gxo" secondAttribute="bottom" constant="20" id="rok-CN-tSa"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="DAf-P6-gxo" secondAttribute="trailing" constant="16" id="wrh-Fe-YbY"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="FbJ-Xt-xrO" appends="YES" id="3DD-2E-ImW"/>
</connections>
</view>
<connections>
<outlet property="searchTextField" destination="t0w-LP-RY2" id="Irt-Es-qdI"/>
<outlet property="sendButton" destination="D5u-KK-Hm1" id="2bT-2z-trO"/>
<outlet property="textColorModifyButton" destination="4Fj-lC-uWo" id="AhN-lB-Zwm"/>
<outlet property="textLabel" destination="T7G-7J-t6N" id="8m1-AD-Zmy"/>
<outlet property="topView" destination="DAf-P6-gxo" id="6uj-w2-dCo"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
<tapGestureRecognizer id="FbJ-Xt-xrO">
<connections>
<action selector="gestureTapped:" destination="BYZ-38-t0r" id="8DH-Ju-qcw"/>
</connections>
</tapGestureRecognizer>
</objects>
<point key="canvasLocation" x="118" y="-2"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
104 changes: 104 additions & 0 deletions LEDBoard/BoardViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// BoardViewController.swift
// LEDBoard
//
// Created by 백래훈 on 2023/07/24.
//

import UIKit

class BoardViewController: UIViewController {

@IBOutlet var topView: UIView!

@IBOutlet var searchTextField: UITextField!

@IBOutlet var sendButton: UIButton!
@IBOutlet var textColorModifyButton: UIButton!

@IBOutlet var textLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
designTopView()
designSearchTextField()
designSendButton()
designTextColorModifyButton()
designTextLabel()

}

// gesture 함수
@IBAction func gestureTapped(_ sender: UITapGestureRecognizer) {
view.endEditing(true)
topView.isHidden = topView.isHidden == true ? false : true
}

// keyboard return tap 함수
@IBAction func keyboardReturnKeyTapped(_ sender: UITextField) {
textLabel.text = searchTextField.text
view.endEditing(true)
}

// 보내기 버튼 액션 함수
@IBAction func sendButtonTapped(_ sender: UIButton) {
textLabel.text = searchTextField.text
view.endEditing(true)
}

// 랜덤 컬러 버튼 액션 함수
@IBAction func setRandomColor(_ sender: UIButton) {
textLabel.textColor = setRandomColor()
}

// 각 디자인 함수들
func designTopView() {
topView.layer.cornerRadius = 5
}

func designSearchTextField() {
searchTextField.placeholder = "내용을 입력해주세요."
searchTextField.borderStyle = .none
searchTextField.addLeftPadding()
searchTextField.font = .systemFont(ofSize: 15, weight: .regular)
}

func designSendButton() {
sendButton.layer.cornerRadius = 10
sendButton.layer.borderColor = UIColor.black.cgColor
sendButton.layer.borderWidth = 1

let attributedTitle = NSAttributedString(
string: "보내기",
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15, weight: .regular),
NSAttributedString.Key.foregroundColor: UIColor.black])
sendButton.setAttributedTitle(attributedTitle, for: .normal)
}

func designTextColorModifyButton() {
textColorModifyButton.layer.cornerRadius = 10
textColorModifyButton.layer.borderColor = UIColor.black.cgColor
textColorModifyButton.layer.borderWidth = 1

let attributedTitle = NSAttributedString(
string: "Aa",
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15, weight: .regular),
NSAttributedString.Key.foregroundColor: UIColor.red])
textColorModifyButton.setAttributedTitle(attributedTitle, for: .normal)
}

func designTextLabel() {
textLabel.font = .systemFont(ofSize: 60, weight: .semibold)
textLabel.textColor = setRandomColor()
}

// UIColor를 rgb 값으로 랜덤하게 설정해주는 함수
func setRandomColor() -> UIColor {
let red = Int.random(in: 0...255)
let green = Int.random(in: 0...255)
let blue = Int.random(in: 0...255)

return UIColor(red: CGFloat(red)/255, green: CGFloat(green)/255, blue: CGFloat(blue)/255, alpha: 1.0)
}

}
16 changes: 16 additions & 0 deletions LEDBoard/UITextField+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// UITextField+.swift
// LEDBoard
//
// Created by 백래훈 on 2023/07/24.
//

import UIKit

extension UITextField {
func addLeftPadding() {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: self.frame.height))
self.leftView = paddingView
self.leftViewMode = ViewMode.always
}
}

0 comments on commit 5ebc1f9

Please sign in to comment.