-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. AutoLayout으로 제약조건 설정하기 2. keyboard 내리기 -> return key / gesture tap 3. 컬러 버튼 클릭 시 -> textLabel Color 랜덤하게 변경하기 4. 비어있는 뷰 클릭 시 -> 상단뷰(topView) isHidden 값 처리하기 (수업시간에 배운 4가지의 방법 참고)
- Loading branch information
Showing
7 changed files
with
217 additions
and
6 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -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> |
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,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) | ||
} | ||
|
||
} |
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,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 | ||
} | ||
} |