-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Edit writeView ScrollView -> UICollectionView
- Loading branch information
1 parent
72da9d1
commit 8517e46
Showing
5 changed files
with
154 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// CategoryCell.swift | ||
// KNU_CSE | ||
// | ||
// Created by junseok on 2021/08/03. | ||
// | ||
|
||
import UIKit | ||
|
||
class CategoryCell : UICollectionViewCell { | ||
var titleLabel = UILabel() | ||
static let identifier = "CategoryCell" | ||
|
||
static func fittingSize(name: String) -> CGSize { | ||
let cell = CategoryCell() | ||
cell.setTitle(title: name) | ||
|
||
let cellheight = cell.titleLabel.font.lineHeight + 10 | ||
let targetSize = CGSize(width: UIView.layoutFittingCompressedSize.width, height: cellheight) | ||
return cell.contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .fittingSizeLevel, verticalFittingPriority: .required) | ||
} | ||
|
||
override var isSelected: Bool { | ||
willSet { | ||
if newValue { | ||
self.titleLabel.textColor = .white | ||
self.contentView.backgroundColor = Color.mainColor.withAlphaComponent(0.65) | ||
} else { | ||
self.titleLabel.textColor = .lightGray | ||
self.contentView.backgroundColor = .white | ||
} | ||
} | ||
} | ||
|
||
override func prepareForReuse() { | ||
//isSelected = false | ||
} | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
draw() | ||
self.isSelected = false | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func draw(){ | ||
initUI() | ||
addView() | ||
setUpConstraints() | ||
} | ||
|
||
func initUI(){ | ||
self.contentView.layer.borderWidth = 0.3 | ||
self.contentView.layer.cornerRadius = 10 | ||
self.contentView.layer.borderColor = UIColor.lightGray.cgColor | ||
|
||
} | ||
|
||
func addView(){ | ||
self.contentView.addSubview(titleLabel) | ||
} | ||
|
||
func setUpConstraints(){ | ||
titleLabel.snp.makeConstraints{ make in | ||
make.left.right.equalToSuperview().inset(10) | ||
make.top.bottom.equalToSuperview().inset(4) | ||
} | ||
} | ||
} | ||
|
||
extension CategoryCell{ | ||
func setTitle(title: String) { | ||
titleLabel.text = title | ||
titleLabel.textAlignment = .center | ||
titleLabel.font = UIFont.systemFont(ofSize: 15, weight: .semibold) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters