Skip to content

Commit

Permalink
Merge pull request #4 from Crois0509/crois-Lv2
Browse files Browse the repository at this point in the history
[Lv2 ~ Lv3] 필수기능 구현
  • Loading branch information
Crois0509 authored Dec 8, 2024
2 parents 1cdb097 + 1c7dde6 commit 2748363
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@ PokemonPhoneBook/PokemonPhoneBook.xcodeproj/project.pbxproj
PokemonPhoneBook/PokemonPhoneBook.xcodeproj/project.xcworkspace/xcuserdata/jangsang-gyeong.xcuserdatad/UserInterfaceState.xcuserstate
PokemonPhoneBook/PokemonPhoneBook.xcodeproj/project.xcworkspace/xcuserdata/jangsang-gyeong.xcuserdatad/UserInterfaceState.xcuserstate
*.xcuserstate
*.xcuserstate
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// PhoneBookData+CoreDataClass.swift
// PokemonPhoneBook
//
// Created by 장상경 on 12/8/24.
//
//

import Foundation
import CoreData

@objc(PhoneBookData)
public class PhoneBookData: NSManagedObject {
static let className: String = "PhoneBookData"
enum Key {
static let name: String = "name"
static let number: String = "number"
static let profile: String = "profile"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// PhoneBookData+CoreDataProperties.swift
// PokemonPhoneBook
//
// Created by 장상경 on 12/8/24.
//
//

import Foundation
import CoreData


extension PhoneBookData {

@nonobjc public class func fetchRequest() -> NSFetchRequest<PhoneBookData> {
return NSFetchRequest<PhoneBookData>(entityName: "PhoneBookData")
}

@NSManaged public var name: String?
@NSManaged public var number: String?
@NSManaged public var profile: Data?

}

extension PhoneBookData : Identifiable {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="false" userDefinedModelVersionIdentifier="">
<elements/>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B91" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="PhoneBookData" representedClassName="PhoneBookData" syncable="YES">
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="number" optional="YES" attributeType="String"/>
<attribute name="profile" optional="YES" attributeType="Binary"/>
</entity>
</model>
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private extension PhoneBookCell {
self.numberLabel.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.trailing.equalToSuperview()
$0.leading.equalTo(self.nameLabel.snp.trailing)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//
// PhoneBookViewController.swift
// PokemonPhoneBook
//
// Created by 장상경 on 12/6/24.
//

import UIKit
import SnapKit

// SubViewController
final class PhoneBookViewController: UIViewController {

// MARK: - PhoneBookViewController UI
private let profileImageView = UIImageView()
private let profileImageRandomChangeButton = UIButton()
private let nameTextField = UITextField()
private let numberTextField = UITextField()

// MARK: - PhoneBookViewController Life Cycle
override func viewDidLoad() {
super.viewDidLoad()

configUI()
}
}

// MARK: - PhoneBookViewController Private Method
private extension PhoneBookViewController {
/// 서브 뷰의 모든 UI 요소를 배치 및 설정
func configUI() {
view.backgroundColor = .white

[self.profileImageView,
self.profileImageRandomChangeButton,
self.nameTextField,
self.numberTextField].forEach { view.addSubview($0) }

setupImageView()
setupChangeButton()
setupTextField()
setupNavigationTitle()
setupNavigationRightButton()
setupUILayout()
}

/// 프로필 이미지를 세팅하는 메소드
func setupImageView() {
self.profileImageView.contentMode = .scaleAspectFit
self.profileImageView.backgroundColor = .clear
self.profileImageView.layer.cornerRadius = 100
self.profileImageView.clipsToBounds = true
self.profileImageView.layer.borderColor = UIColor.gray.cgColor
self.profileImageView.layer.borderWidth = 2
}

/// 텍스트필드를 세팅하는 메소드
func setupTextField() {
[self.nameTextField, self.numberTextField].forEach {
$0.font = UIFont.systemFont(ofSize: 15, weight: .light)
$0.borderStyle = .roundedRect
$0.textColor = .black
$0.keyboardType = .default
}
self.nameTextField.placeholder = "이름을 입력해 주세요"
self.numberTextField.placeholder = "전화번호를 입력해 주세요"
}

/// 프로필 이미지 변경 버튼을 세팅하는 메소드
func setupChangeButton() {
var config = UIButton.Configuration.plain()

var titleAttr = AttributedString.init("랜덤 이미지 생성")
titleAttr.font = .systemFont(ofSize: 20, weight: .medium)

config.attributedTitle = titleAttr
config.baseForegroundColor = .gray

self.profileImageRandomChangeButton.configuration = config
self.profileImageRandomChangeButton.backgroundColor = .clear
self.profileImageRandomChangeButton.addTarget(self, action: #selector(changeProfileImage), for: .touchDown)
}

/// 프로필 이미지를 랜덤으로 변경하는 메소드
@objc func changeProfileImage() {

}

/// 서브 뷰의 모든 UI 레이아웃을 설정하는 메소드
func setupUILayout() {
self.profileImageView.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide).offset(10)
$0.centerX.equalToSuperview()
$0.width.height.equalTo(200)
}

self.profileImageRandomChangeButton.snp.makeConstraints {
$0.top.equalTo(self.profileImageView.snp.bottom).offset(10)
$0.centerX.equalToSuperview()
$0.width.equalTo(200)
$0.height.equalTo(50)
}

self.nameTextField.snp.makeConstraints {
$0.top.equalTo(self.profileImageRandomChangeButton.snp.bottom).offset(10)
$0.centerX.equalToSuperview()
$0.width.equalTo(300)
$0.height.equalTo(40)
}

self.numberTextField.snp.makeConstraints {
$0.top.equalTo(self.nameTextField.snp.bottom).offset(15)
$0.centerX.equalToSuperview()
$0.width.equalTo(300)
$0.height.equalTo(40)
}
}

/// 네비게이션 타이틀을 설정하는 메소드
func setupNavigationTitle() {
let title = UILabel()
title.text = "연락처 추가"
title.textColor = .black
title.font = UIFont.systemFont(ofSize: 25, weight: .bold)
title.textAlignment = .center
title.backgroundColor = .clear

self.navigationItem.titleView = title
}

/// 네비게이션바의 오른쪽 버튼을 세팅하는 메소드
func setupNavigationRightButton() {
let rightButton = UIBarButtonItem(title: "적용", style: .plain, target: self, action: #selector(savePhoneNumber))
self.navigationItem.rightBarButtonItem = rightButton
}

/// 현재 입력한 정보를 저장하는 메소드
@objc func savePhoneNumber() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@
import UIKit
import SnapKit

// Main ViewController
final class ViewController: UIViewController {

// MARK: - ViewController UI
private let tableView = UITableView()

private let navigationTitle = UILabel()

private let pushButton = UIButton()

// MARK: - ViewController Life Cycle
override func viewDidLoad() {
super.viewDidLoad()

configUI()
configUI() // UI 세팅
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

self.navigationController?.navigationBar.isHidden = true // 뷰가 생성될 때마다 네비게이션 바 히든
}
}

// MARK: - ViewController Private Method
private extension ViewController {

/// 뷰의 모든 UI를 세팅하는 메소드
func configUI() {
view.backgroundColor = .white
self.navigationController?.navigationBar.isHidden = true
[self.tableView,
self.navigationTitle,
self.pushButton].forEach { view.addSubview($0) }
Expand All @@ -37,19 +48,7 @@ private extension ViewController {
setupUILayout()
}

func setupPushButtonView() {
var config = UIButton.Configuration.plain()

var titleAttr = AttributedString.init("추가")
titleAttr.font = .systemFont(ofSize: 20, weight: .medium)

config.attributedTitle = titleAttr
config.baseForegroundColor = .systemBlue

self.pushButton.configuration = config
self.pushButton.backgroundColor = .clear
}

/// 네비게이션 타이블 UI를 세팅하는 메소드
func setupNavigationTitle() {
navigationTitle.text = "친구 목록"
navigationTitle.font = UIFont.systemFont(ofSize: 25, weight: .bold)
Expand All @@ -58,6 +57,7 @@ private extension ViewController {
navigationTitle.backgroundColor = .clear
}

/// 테이블 뷰의 UI를 세팅하는 메소드
func setupTableView() {
self.tableView.delegate = self
self.tableView.dataSource = self
Expand All @@ -68,14 +68,38 @@ private extension ViewController {
self.tableView.separatorInset.right = 20
}

/// 버튼의 UI를 세팅하는 메소드
func setupPushButtonView() {
var config = UIButton.Configuration.plain()

var titleAttr = AttributedString.init("추가")
titleAttr.font = .systemFont(ofSize: 20, weight: .medium)

config.attributedTitle = titleAttr
config.baseForegroundColor = .systemBlue

self.pushButton.configuration = config
self.pushButton.backgroundColor = .clear
self.pushButton.addTarget(self, action: #selector(pushDestinationView), for: .touchUpInside)
}

/// 버튼의 액션 메소드
/// 버튼을 누르면 PhoneBookViewController 뷰가 쌓임
@objc func pushDestinationView() {
self.navigationController?.pushViewController(PhoneBookViewController(), animated: true)
self.navigationController?.navigationBar.isHidden = false // 뷰가 쌓이면 네이게이션바를 보여줌
}

/// 뷰의 모든 레이아웃을 세팅하는 메소드
func setupUILayout() {
self.navigationTitle.snp.makeConstraints {
$0.top.trailing.leading.equalTo(view.safeAreaLayoutGuide)
$0.trailing.leading.equalTo(view.safeAreaLayoutGuide)
$0.top.equalTo(view.safeAreaLayoutGuide).offset(-10)
$0.height.equalTo(60)
}

self.tableView.snp.makeConstraints {
$0.trailing.leading.bottom.equalTo(view.safeAreaLayoutGuide)
$0.trailing.leading.bottom.equalTo(view)
$0.top.equalTo(self.navigationTitle.snp.bottom).inset(10)
}

Expand All @@ -86,11 +110,15 @@ private extension ViewController {
}
}

// MARK: - ViewController TableView DataSource Method
extension ViewController: UITableViewDataSource {

// 테이블뷰의 셀 수
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}

// 테이블뷰 셀 설정
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = self.tableView.dequeueReusableCell(withIdentifier: PhoneBookCell.id) as? PhoneBookCell else {
return UITableViewCell()
Expand All @@ -101,19 +129,23 @@ extension ViewController: UITableViewDataSource {
return cell
}

// 테이블뷰 셀 높이 설정
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}

// 테이블뷰 헤더 크기
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
}

// 테이블뷰 헤더 설정 = nil (표시하지 않음)
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}
}

// MARK: - ViewController TableView Delegate Method
extension ViewController: UITableViewDelegate {

}

0 comments on commit 2748363

Please sign in to comment.