Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 프로그래머스 조건에 맞게 수열 변경하기 3
- cocoapods 설치 오류
- 프로그래머스 n의 배수 고르기
- 객체지향
- n번째 원소까지
- continue
- 프로그래머스 문자열 정렬하기 (1)
- 스페인어
- 스파르타 코딩클럽 내일배움캠프
- 프로그래머스 주사위 게임1
- 프로그래머스 최댓값 만들기(2)
- 주사위 게임1
- 조건에 맞게 수열 변경하기 3
- Error installing cocoapods
- 연산자
- 프로그래머스 암호 해독
- array
- swift
- Til
- 프로그래머스 n번째 원소까지
- Break
- 문자열 정렬하기 (1)
- 스파르타코딩캠프
- 배열 만들기1
- 문자열 붙여서 출력하기
- 프로그래머스 자동커밋
- ruby설치
- 프로그래머스
- 프로그래머스 문자열 붙여서 출력하기
- 프로그래머스 배열 만들기1
Archives
- Today
- Total
dev._.note
[Swift] 커스텀 칩뷰 만들기 본문
프로젝트를 진행하다가 여러가지 데이터를 삭제 추가하는 과정이 많아서
정보를 칩모양으로 담아서 x표시를 넣으면 어떨까해서
커스텀 칩뷰를 만들어봤다
참고한 레퍼런스 (네이버캘린더)
커스텀 칩뷰를 적용한 결과물
작성한 커스텀 뷰
class InfoChipView: UIView {
private let textLabel = UILabel()
private var deleteButton: UIButton?
var text: String? {
return textLabel.text
}
weak var delegate: InfoChipViewDelegate?
init(text: String, color: UIColor, showDeleteButton: Bool) {
super.init(frame: .zero)
setupTextLabel(text: text)
setupView(color: color)
if showDeleteButton {
setupDeleteButton()
} else {
textLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10).isActive = true
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupTextLabel(text: String) {
textLabel.text = text
textLabel.textColor = .black
addSubview(textLabel)
textLabel.translatesAutoresizingMaskIntoConstraints = false
textLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 10).isActive = true
textLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
}
private func setupDeleteButton() {
let button = UIButton()
button.setImage(UIImage(systemName: "multiply"), for: .normal)
button.tintColor = .black
button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside)
addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
button.leadingAnchor.constraint(equalTo: textLabel.trailingAnchor, constant: 10).isActive = true
button.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -10).isActive = true
button.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
self.deleteButton = button
}
private func setupView(color: UIColor) {
backgroundColor = color
layer.cornerRadius = 3
clipsToBounds = true
}
@objc private func deleteButtonTapped() {
delegate?.didTapDeleteButton(in: self)
}
}
'Dev > SWIFT' 카테고리의 다른 글
[Swift] UIDatePicker (0) | 2024.03.20 |
---|---|
[Swift] 모든 테이블뷰 컨텐츠에 동일하게 마진값 적용 (0) | 2024.03.14 |
[Swift] 테이블뷰 섹션간의 간격 조절 (0) | 2024.03.13 |
[Swift] Gesture Recognizer(재스처 제어) (0) | 2024.03.11 |
[Swift] Mapkit 위치 검색 (0) | 2024.03.08 |