1차 세미나 과제 해결#2
Conversation
hyoring030
left a comment
There was a problem hiding this comment.
다양한 함수에 주석으로 설명이 잘 되어 있어서 이해하기 쉬웠습니다!
많이 배워갑니당 수고하셨습니다! :)
Genesis2010
left a comment
There was a problem hiding this comment.
정말로 고생 많으셨습니다!
코드 스타일이 너무 깔끔하네요!
| // | ||
| // 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 { | ||
|
|
||
| // 텍스트필드의 왼쪽에 이미지를 배치하는 메서드 | ||
| 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 | ||
| } | ||
|
|
There was a problem hiding this comment.
Extension 으로 구현해서 재사용 가능한점 너무 좋습니다!
지금은 2개이지만 갈수록 많아진다면 Extension 디렉토리에서 각각의 UIComponent 에 대해 구현하는 것이 좋은 방법이라 생각합니다!
| 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 | ||
| } | ||
|
|
There was a problem hiding this comment.
레아아웃에 대한 코드를 따로 함수로 구현하셨네요! 너무 좋은 방법입니다!!
움.. 저만의 생각입니다만! viewDidLoad 아래에 구현하면 더욱 일관성있어 보일거 같아요!
chaentopia
left a comment
There was a problem hiding this comment.
extension도 사용하시고 너무너무 좋네요!! 코드리뷰 남겨두었습니다 확인해보세용
고생하셨습니다 🤩
|
|
||
| } | ||
|
|
||
| extension UITextField { |
There was a problem hiding this comment.
extension을 파일로 따로 빼서 쓰는 경우
UIImage+.swift 파일과 UITextField+.swift 파일로 나누어서 작성해도 좋을 것 같아요~~
대체로 extension 파일의 경우
어쩌고+.swift 혹은 어쩌고+extension.swift 등의 파일명을 사용합니다!
| @IBOutlet weak var passwordLabel: UILabel! | ||
| @IBOutlet weak var backButton: UIButton! | ||
|
|
||
| func setViewStyle() { |
There was a problem hiding this comment.
가볍게 setStyle() 을 함수명으로 쓰기도 합니다!
저 같은 경우에는 레이아웃과 스타일을 잡는 메소드를 합쳐서 setUI()에 넣어요
func setUI() {
setStyle()
setLayout()
}
✨ 해결한 이슈
#1
🛠️ 작업내용
UIImageView추가extension(이미지 크기 조정, UITextField 왼쪽에 이미지 추가 메서드) 추가clearButtonMode적용cornerRadius변경Simulator.Screen.Recording.-.iPhone.15.Pro.-.2023-10-11.at.19.10.01.mp4
🖥️ 주요 코드 설명
1. UIImage extension - 이미지 크기를 원하는대로 조정하는 메서드
2. UITextField extension - UITextField 왼쪽에 이미지를 배치하는 메서드
3. 사용 예시
📌 리뷰 포인트
setViewStyle로 지었는데 더 나은 함수명을 알고 계신다면 알려주세요!✅ 체크리스트