Skip to content

Commit

Permalink
Merge pull request #37 from Nice-Duck/feature/custom_textfield
Browse files Browse the repository at this point in the history
[#36]Feat: 커스텀 서치 바 구현
  • Loading branch information
Minny27 authored Oct 20, 2022
2 parents cbaf271 + 179b32f commit 3ccc7d5
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 33 deletions.
18 changes: 18 additions & 0 deletions Sparky-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
56A0AA7628FC3BE100726C13 /* SparkyNavBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A0AA7428FC3AD400726C13 /* SparkyNavBar.swift */; };
56A0AA7728FC3BE200726C13 /* SparkyNavBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A0AA7428FC3AD400726C13 /* SparkyNavBar.swift */; };
56A6FAF328E4BB4B009EA038 /* SignUpVC2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A6FAF228E4BB4B009EA038 /* SignUpVC2.swift */; };
56C41B8828FEC81900D610E5 /* SparkySearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C41B8728FEC81900D610E5 /* SparkySearchBar.swift */; };
56C41B8928FEC8CC00D610E5 /* SparkySearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C41B8728FEC81900D610E5 /* SparkySearchBar.swift */; };
56C41B8C28FECED600D610E5 /* MyScrapVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C41B8B28FECED600D610E5 /* MyScrapVC.swift */; };
56C7B20328E93D9800D638D2 /* UserServiceAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C7B20228E93D9800D638D2 /* UserServiceAPI.swift */; };
56C7B20528E9463600D638D2 /* UserServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C7B20428E9463600D638D2 /* UserServiceProvider.swift */; };
56C7B20728E9687600D638D2 /* EmailSignInViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56C7B20628E9687600D638D2 /* EmailSignInViewModel.swift */; };
Expand Down Expand Up @@ -161,6 +164,8 @@
56A0AA6E28FBD50F00726C13 /* TagBottomSheetVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagBottomSheetVC.swift; sourceTree = "<group>"; };
56A0AA7428FC3AD400726C13 /* SparkyNavBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SparkyNavBar.swift; sourceTree = "<group>"; };
56A6FAF228E4BB4B009EA038 /* SignUpVC2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpVC2.swift; sourceTree = "<group>"; };
56C41B8728FEC81900D610E5 /* SparkySearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SparkySearchBar.swift; sourceTree = "<group>"; };
56C41B8B28FECED600D610E5 /* MyScrapVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyScrapVC.swift; sourceTree = "<group>"; };
56C7B20228E93D9800D638D2 /* UserServiceAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserServiceAPI.swift; sourceTree = "<group>"; };
56C7B20428E9463600D638D2 /* UserServiceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserServiceProvider.swift; sourceTree = "<group>"; };
56C7B20628E9687600D638D2 /* EmailSignInViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailSignInViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,6 +260,7 @@
560BF31A28D0D0F400438463 /* Scenes */ = {
isa = PBXGroup;
children = (
56C41B8A28FECEC200D610E5 /* MyScrap */,
56DE426328E1F865000A6A55 /* SignUp */,
560BF31F28D0E66400438463 /* Home */,
560BF31E28D0E65900438463 /* Signin */,
Expand Down Expand Up @@ -465,10 +471,19 @@
isa = PBXGroup;
children = (
56A0AA7428FC3AD400726C13 /* SparkyNavBar.swift */,
56C41B8728FEC81900D610E5 /* SparkySearchBar.swift */,
);
path = NavigationBar;
sourceTree = "<group>";
};
56C41B8A28FECEC200D610E5 /* MyScrap */ = {
isa = PBXGroup;
children = (
56C41B8B28FECED600D610E5 /* MyScrapVC.swift */,
);
path = MyScrap;
sourceTree = "<group>";
};
56DE426328E1F865000A6A55 /* SignUp */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -772,6 +787,7 @@
5684384E28F5D83C000E5C89 /* TagCollectionViewCell.swift in Sources */,
5652A44628EB303F00415738 /* CrawlManager.swift in Sources */,
5616C54828DB739800BF7126 /* CustomShareNC.swift in Sources */,
56C41B8928FEC8CC00D610E5 /* SparkySearchBar.swift in Sources */,
5684384F28F5D96E000E5C89 /* Tag.swift in Sources */,
569B79CB28F9F2A000AD9BC3 /* TagCollectionViewFlowLayout.swift in Sources */,
);
Expand Down Expand Up @@ -808,12 +824,14 @@
560BF31D28D0DAB300438463 /* UITextField+.swift in Sources */,
56DE426928E20E9A000A6A55 /* SignUpVC4.swift in Sources */,
5652A44D28EB4FAA00415738 /* Strings.swift in Sources */,
56C41B8C28FECED600D610E5 /* MyScrapVC.swift in Sources */,
56DE426728E20E91000A6A55 /* SignUpVC3.swift in Sources */,
56A0AA7728FC3BE200726C13 /* SparkyNavBar.swift in Sources */,
56902D1C28EAC595005F18B1 /* OTPStackView.swift in Sources */,
567DF87428ECA69F005A3E30 /* EmailSendRequest.swift in Sources */,
56C7B20928E9710400D638D2 /* EmailSignInView.swift in Sources */,
564938F928E8B55E00861D26 /* EmailSignInRequest.swift in Sources */,
56C41B8828FEC81900D610E5 /* SparkySearchBar.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
70 changes: 70 additions & 0 deletions Sparky-iOS/Custom/NavigationBar/SparkySearchBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// SparkyTextField.swift
// Sparky-iOS
//
// Created by SeungMin on 2022/10/18.
//

import UIKit

class SparkyTextField: UITextField {

override init(frame: CGRect) {
super.init(frame: frame)

// setupUI()
setupUnderLine()
}

// required init?(coder: NSCoder) {
// super.init(coder: coder)
//
// setupUnderLine()
// }

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// private func setupUI() {
// $0.
//
// setupUnderLine()
// }

private func setupUnderLine() {
let bottomLayer = CALayer()
bottomLayer.frame = CGRect(x: 0,
y: self.frame.height,
width: self.frame.width,
height: 1)
bottomLayer.backgroundColor = UIColor.gray400.cgColor
self.layer.addSublayer(bottomLayer)
}

func setupLeftImageView(image: UIImage) {
self.leftViewMode = .always
let leftImageView = UIImageView(frame: CGRect(x: 0,
y: self.frame.height / 2 - 10,
width: 16,
height: 16))
leftImageView.tintColor = .gray400
leftImageView.image = image
self.addSubview(leftImageView)
}

override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
let bounds = CGRect(x: 24, y: bounds.size.height / 2 - 10, width: bounds.width, height: bounds.height)
return bounds
}

override func editingRect(forBounds bounds: CGRect) -> CGRect {
let bounds = CGRect(x: 24, y: bounds.size.height / 2 - 10, width: bounds.width, height: bounds.height)
return bounds
}

override func textRect(forBounds bounds: CGRect) -> CGRect {
let bounds = CGRect(x: 24, y: bounds.size.height / 2 - 10, width: bounds.width, height: bounds.height)
return bounds
}
}
35 changes: 13 additions & 22 deletions Sparky-iOS/Custom/Shareing/TagBottomSheetVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ final class TagBottomSheetVC: UIViewController {
$0.style = .plain
}

private let tagSearchBar = UISearchBar().then {
private let tagTextField = SparkyTextField(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 40, height: 24)).then {
$0.placeholder = "검색할 태그를 입력해주세요(최대 7글자)"
$0.showsCancelButton = false
$0.isTranslucent = false
$0.searchBarStyle = .minimal
$0.setBackgroundImage(UIImage(), for: .bottom, barMetrics: .default)

for view in $0.searchTextField.subviews {
view.backgroundColor = .sparkyWhite
}

$0.setupLeftImageView(image: UIImage(named: "search")!)
}

private let recentTagTitleLabel = UILabel().then {
Expand All @@ -79,9 +71,9 @@ final class TagBottomSheetVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .white
view.backgroundColor = .background
setupNavBar()
setupConstraintes()
setupConstraints()
bindViewModel()
setupCollectionViewDelegate()
setupDimmendTabGesture()
Expand All @@ -104,10 +96,10 @@ final class TagBottomSheetVC: UIViewController {
customNavBar.layoutIfNeeded()
}

private func setupConstraintes() {
private func setupConstraints() {
view.addSubview(dimmedView)
dimmedView.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.top.equalTo(view)
$0.left.equalTo(view)
$0.bottom.equalTo(view)
$0.right.equalTo(view)
Expand All @@ -131,17 +123,16 @@ final class TagBottomSheetVC: UIViewController {
$0.right.equalTo(tagBottomSheetView)
}

tagBottomSheetView.addSubview(tagSearchBar)
tagSearchBar.snp.makeConstraints {
$0.top.equalTo(customNavBar.snp.bottom).offset(11)
$0.left.equalTo(tagBottomSheetView).offset(4)
$0.right.equalTo(tagBottomSheetView).offset(-4)
$0.height.equalTo(44)
tagBottomSheetView.addSubview(tagTextField)
tagTextField.snp.makeConstraints {
$0.top.equalTo(customNavBar.snp.bottom).offset(12)
$0.left.equalTo(tagBottomSheetView).offset(20)
$0.right.equalTo(tagBottomSheetView).offset(-20)
}

tagBottomSheetView.addSubview(recentTagTitleLabel)
recentTagTitleLabel.snp.makeConstraints {
$0.top.equalTo(tagSearchBar.snp.bottom).offset(16)
$0.top.equalTo(tagTextField.snp.bottom).offset(16)
$0.left.equalTo(tagBottomSheetView).offset(20)
}

Expand All @@ -156,7 +147,7 @@ final class TagBottomSheetVC: UIViewController {
private func bindViewModel() {
viewModel.filterTagList = viewModel.recentTagList

tagSearchBar.searchTextField.rx.text
tagTextField.rx.text
.orEmpty
.subscribe(onNext: { text in
print("text - \(text.description)")
Expand Down
2 changes: 2 additions & 0 deletions Sparky-iOS/Custom/Shareing/TagCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import RxSwift
import RxCocoa

final class TagCollectionViewModel {

var tagList = BehaviorRelay<[Tag]>(value: [
Tag(text: "디자인", backgroundColor: .sparkyOrange, buttonType: .delete),
Tag(text: "시각디자인", backgroundColor: .sparkyPink, buttonType: .delete),
Expand All @@ -27,6 +28,7 @@ final class TagCollectionViewModel {
Tag(text: "태그추가", backgroundColor: .clear, buttonType: .add)
])


func didTapDeleteButton(index: Int) {
var tagListCopy = self.tagList.value
tagListCopy.remove(at: index)
Expand Down
1 change: 1 addition & 0 deletions Sparky-iOS/Extension/Color+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension UIColor {
static let sparkyGreen: UIColor = UIColor(named: "sparkyGreen")!
static let sparkyBlue: UIColor = UIColor(named: "sparkyBlue")!
static let sparkyPink: UIColor = UIColor(named: "sparkyPink")!
static let background: UIColor = UIColor(named: "background")!
static let gray100: UIColor = UIColor(named: "gray100")!
static let gray200: UIColor = UIColor(named: "gray200")!
static let gray300: UIColor = UIColor(named: "gray300")!
Expand Down
1 change: 0 additions & 1 deletion Sparky-iOS/Manager/CrawlManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ final class CrwalManager {
scrap = Scrap(thumbnailURL: thumbnailURL,
title: title,
subTitle: subTitle)
print("scrap - \(scrap)")
completion(scrap)
} catch {
print(NetworkError.parsingError)
Expand Down
13 changes: 8 additions & 5 deletions Sparky-iOS/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
self.window = UIWindow(windowScene: scene)
self.window?.overrideUserInterfaceStyle = .light

let rootViewController = UINavigationController(rootViewController: SignInVC())
let rootViewController: UINavigationController

if let _ = TokenUtils().read("com.sparky.token", account: "accessToken") {
rootViewController = UINavigationController(rootViewController: HomeVC())
} else {
rootViewController = UINavigationController(rootViewController: SignInVC())
}

window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
}

@objc private func didTapBackButton() {

}

func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
Expand Down
59 changes: 57 additions & 2 deletions Sparky-iOS/Scenes/Home/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,71 @@
//

import UIKit
import RxSwift
import RxCocoa

class HomeVC: UIViewController {
final class HomeVC: UIViewController {

// MARK: - Properties
private let disposeBag = DisposeBag()

private let scrapTextField = SparkyTextField(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 40, height: 24)).then {

$0.placeholder = "검색어를 입력해주세요"
$0.setupLeftImageView(image: UIImage(named: "search")!)
$0.leftView?.tintColor = .gray400
}

private let myScrapTitleLabel = UILabel().then({
$0.text = "내 스크랩"
$0.font = .subTitleBold1
$0.textAlignment = .center
$0.textColor = .sparkyBlack
})


// MARK: - LifeCycles
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .orange

view.backgroundColor = .background
setupNavBar()
setupConstraints()
}

private func setupNavBar() {
let logoButtonItem = UIBarButtonItem(image: UIImage(named: "logo"),
style: .done,
target: self,
action: nil)
logoButtonItem.tintColor = .sparkyBlack

let profileButtonItem = UIBarButtonItem(image: UIImage(named: "profile"),
style: .plain,
target: self,
action: nil)
profileButtonItem.tintColor = .none
profileButtonItem.rx.tap
.subscribe { _ in
self.navigationController?.pushViewController(MyScrapVC(), animated: true)
}.disposed(by: disposeBag)

navigationItem.leftBarButtonItem = logoButtonItem
navigationItem.rightBarButtonItem = profileButtonItem
}

private func setupConstraints() {
view.addSubview(scrapTextField)
scrapTextField.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide).offset(12)
$0.left.equalTo(view).offset(20)
$0.right.equalTo(view).offset(-20)
}

view.addSubview(myScrapTitleLabel)
myScrapTitleLabel.snp.makeConstraints {
$0.top.equalTo(scrapTextField.snp.bottom).offset(18)
$0.left.equalTo(view).offset(20)
}
}
}
21 changes: 21 additions & 0 deletions Sparky-iOS/Scenes/MyScrap/MyScrapVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// MyScrapVC.swift
// Sparky-iOS
//
// Created by SeungMin on 2022/10/18.
//

import UIKit

final class MyScrapVC: UIViewController {

// MARK: - Properties


// MARK: - LifeCycles
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .sparkyGreen
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.969",
"green" : "0.976",
"red" : "0.980"
}
},
"idiom" : "iphone"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 3ccc7d5

Please sign in to comment.