Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1차 세미나 과제 해결 #2

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "key.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Logo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "mail.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions sopt33-first-seminar/sopt33-first-seminar/Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Extension.swift
// sopt33-first-seminar
//
// Created by 티모시 킴 on 10/11/23.
//

import UIKit

extension UIImage {

// 이미지를 원하는 크기로 조정하는 메서드
func resizeImageTo(size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
self.draw(in: CGRect(origin: CGPoint.zero, size: size))
guard let resizedImage = UIGraphicsGetImageFromCurrentImageContext() else {
return nil
}
UIGraphicsEndImageContext()
return resizedImage
}

}

extension UITextField {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension을 파일로 따로 빼서 쓰는 경우
UIImage+.swift 파일과 UITextField+.swift 파일로 나누어서 작성해도 좋을 것 같아요~~
대체로 extension 파일의 경우
어쩌고+.swift 혹은 어쩌고+extension.swift 등의 파일명을 사용합니다!


// 텍스트필드의 왼쪽에 이미지를 배치하는 메서드
func addLeftImage(image : UIImage){
let imageView = UIImageView(frame: CGRect(x: 10, y: 0, width: image.size.width, height: image.size.height))
let view = UIView(frame: CGRect(x: 0, y: 0, width: image.size.width + 20, height: image.size.height))
imageView.image = image
view.addSubview(imageView)
self.leftView = view
self.leftViewMode = .always
}

Comment on lines +1 to +36

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extension 으로 구현해서 재사용 가능한점 너무 좋습니다!
지금은 2개이지만 갈수록 많아진다면 Extension 디렉토리에서 각각의 UIComponent 에 대해 구현하는 것이 좋은 방법이라 생각합니다!

}
14 changes: 10 additions & 4 deletions sopt33-first-seminar/sopt33-first-seminar/ResultVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ class ResultVC: UIViewController {
var loginDataCompletion: ((([String]) -> Void)?) // 매개변수 타입: String 배열, 리턴타입: void

@IBOutlet weak var emailLabel: UILabel!
@IBOutlet weak var passwordLabel: UILabel!
@IBOutlet weak var backButton: UIButton!

func setViewStyle() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가볍게 setStyle() 을 함수명으로 쓰기도 합니다!
저 같은 경우에는 레이아웃과 스타일을 잡는 메소드를 합쳐서 setUI()에 넣어요

func setUI() {
    setStyle()
    setLayout()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 setUI를 viewDidLoad() 안에 넣습니다

emailLabel.font = UIFont(name: "SnellRoundhand-Bold", size: 23.0)

backButton.layer.cornerRadius = 5
}

override func viewDidLoad() {
super.viewDidLoad()
bindText()
setViewStyle()
}

// MARK: 화면전환 방식1 - NavigationController (pop)
Expand All @@ -42,8 +49,7 @@ class ResultVC: UIViewController {
}

private func bindText() {
self.emailLabel.text = "email : \(email)"
self.passwordLabel.text = "password : \(password)"
emailLabel.text = "\(email)"
}

}
16 changes: 16 additions & 0 deletions sopt33-first-seminar/sopt33-first-seminar/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ class ViewController: UIViewController {
private var idText: String = ""
private var passwordText: String = ""

@IBOutlet weak var idTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginButton: UIButton!

func setViewStyle() {
idTextField.addLeftImage(image: (UIImage(named: "Mail")?.resizeImageTo(size: CGSize(width: 25, height: 25)))!)
idTextField.clearButtonMode = .whileEditing

passwordTextField.addLeftImage(image: (UIImage(named: "Key")?.resizeImageTo(size: CGSize(width: 25, height: 25)))!)
passwordTextField.clearButtonMode = .whileEditing
passwordTextField.isSecureTextEntry = true

loginButton.layer.cornerRadius = 5
}

Comment on lines +19 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레아아웃에 대한 코드를 따로 함수로 구현하셨네요! 너무 좋은 방법입니다!!
움.. 저만의 생각입니다만! viewDidLoad 아래에 구현하면 더욱 일관성있어 보일거 같아요!

override func viewDidLoad() {
super.viewDidLoad()
setViewStyle()
}

@IBAction func idTextFieldDidEditing(_ sender: Any) {
Expand Down