[UIKit] : UITextField 키보드 올리고 내리기
2022. 9. 11. 12:43
iOS/UIKit
UITextField에 텍스트를 입력할 때 사용하는 키보드를 올리고, 내려보자 방법은 간단하다 becomeFirstResponder 와 resignFirstResponder를 사용하면 된다. 버튼을 눌렀을 때 키보드를 올리고 내리는 함수를 작성해보자 override func viewDidLoad() { super.viewDidLoad() view.addSubview(textField) view.addSubview(showButton) view.addSubview(hideButton) showButton.addTarget(self, action: #selector(didTapShowButton), for: .touchUpInside) hideButton.addTarget(self, action: #sele..

[UIKit] : TextField 값 실시간으로 가져오기
2022. 9. 11. 12:08
iOS/UIKit
ID 혹은 Password 를 실시간으로 검사하는 기능을 원한다면 이 글을 참고해보자! 우선 텍스트 필드를 띄우고, TextField 속 Text 의 확인을 위한 Label을 만들어준다. class ViewController: UIViewController{ private let textField : UITextField = { let textField = UITextField() textField.placeholder = "문자열 입력" textField.backgroundColor = .cyan return textField }() private let checkLabel : UILabel = { let label = UILabel() label.backgroundColor = .gray label...

[UIKit] : CollectionView Header 만들기 - (UICollectionReusableView)
2022. 9. 2. 16:49
iOS/UIKit
Collection View에서 UICollectionReusableView를 사용하여 header를 만들어보자. 전 글에서 CollectionView 를 만들었으니 코드를 이어서 작성해보자! 참고 : https://seorin-yy.tistory.com/19 [Swift] : CollectionView 생성, Cell 등록하기 정말 많이 사용되는 CollectionView 를 띄워보자. Collection View 를 생성하기 전에 먼저 CollectionView 에서 사용될 Cell 을 만들어보자 UICollectionViewCell를 상속받는 Cell을 생성해주자. 그리고 알 수.. seorin-yy.tistory.com UICollectionReusableView를 사용하여 Header를 만들게 ..

[UIKit] : CollectionView 생성, Cell 등록하기
2022. 9. 2. 16:26
iOS/UIKit
정말 많이 사용되는 CollectionView 를 띄워보자. Collection View 를 생성하기 전에 먼저 CollectionView 에서 사용될 Cell 을 만들어보자 UICollectionViewCell를 상속받는 Cell을 생성해주자. 그리고 알 수 있게 배경화면을 파란색으로 설정해주자 class CollectionViewCell: UICollectionViewCell { static let identifier = "CollectionViewCell" override init(frame: CGRect) { super.init(frame: frame) //Cell에서는 View대신 ContentView를 사용한다 contentView.backgroundColor = .blue } required..
[UIKit] : UIButton 속 이미지 크기 조절하기
2022. 8. 25. 00:01
iOS/UIKit
UIButton에 Image를 넣었을때 Image 크기를 조절해보자. 기본적인 부분이라 쉬울 것 같지만 많은 사람들이 어려워하는 부분이다. 대부분의 경우가 image를 넣어주고 Button 의 사이즈를 조절하려고 하는데 다른 방법을 알아보자! Image 를 만들 때 크기를 크게 해주고 Button 에 추가해주면 된다. UIImage를 크게 만드는 방법은 SymbolConfiguration 를 사용해주면 된다. private let button : UIButton = { let button = UIButton() //Button에 넣어줄 UIImage의 크기를 30으로 정해주자 let config = UIImage.SymbolConfiguration(pointSize: 30) let image = UIIm..
[UIKit] : 구조체 문자열 원하는 문자열로 바꾸기
2022. 8. 24. 22:34
iOS/UIKit
구조체의 문자열을 마음대로 바꿔보자! ex ) "유서린" -> "제 이름은 유서린입니다." 간단한 방법으로는 또 하나의 변수를 만들어서 그 변수에 저장해주는 것이다 struct People{ let name : String var nameString: String { return "제 이름은 \(name)입니다." } } 위 코드처럼 구조체를 만들면 nameString 은 자동으로 완성된다. 전체코드 import UIKit struct People{ let name : String //nameString은 자동으로 완성된다. var nameString: String { return "제 이름은 \(name)입니다." } } class ViewController: UIViewController{ let p..