|
@@ -5,15 +5,19 @@
|
|
|
// Created by 100Years on 2025/4/29.
|
|
|
//
|
|
|
|
|
|
+
|
|
|
+private let itemW = 68.0
|
|
|
+private let itemH = 80.0
|
|
|
+
|
|
|
class TSTTPRatioView:TSBaseView {
|
|
|
|
|
|
- var selectedValueBlock:((TSGenerateStyleModel)->Void)?
|
|
|
-
|
|
|
- var dataArray: [TSGenerateStyleModel] = [TSGenerateStyleModel](){
|
|
|
+ var selectedValueBlock:((AspectRatio)->Void)?
|
|
|
+ var selectRatio:AspectRatio?
|
|
|
+ var dataArray: [AspectRatio] = [AspectRatio](){
|
|
|
didSet{
|
|
|
styleCollectionView.reloadData()
|
|
|
- if dataArray.count > 0 {
|
|
|
- self.styleCollectionView.selectItem(at: self.currentIndexPath, animated: false, scrollPosition: .centeredHorizontally)
|
|
|
+ if let selectRatio = selectRatio,let selectedIndex = dataArray.firstIndex(of: selectRatio) {
|
|
|
+ self.styleCollectionView.selectItem(at: IndexPath(item: selectedIndex, section: 0), animated: false, scrollPosition: .centeredHorizontally)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -21,9 +25,9 @@ class TSTTPRatioView:TSBaseView {
|
|
|
lazy var layout: UICollectionViewFlowLayout = {
|
|
|
let layout = UICollectionViewFlowLayout()
|
|
|
layout.scrollDirection = .horizontal
|
|
|
- layout.itemSize = CGSize(width: 68, height: 80)
|
|
|
- layout.minimumInteritemSpacing = 12.0
|
|
|
- layout.minimumLineSpacing = 0.0
|
|
|
+ layout.itemSize = CGSize(width: itemW, height: itemH)
|
|
|
+ layout.minimumInteritemSpacing = 0.0
|
|
|
+ layout.minimumLineSpacing = 12.0
|
|
|
layout.sectionInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
|
|
|
return layout
|
|
|
}()
|
|
@@ -43,12 +47,9 @@ class TSTTPRatioView:TSBaseView {
|
|
|
return collectionView
|
|
|
}()
|
|
|
|
|
|
- var currentIndexPath:IndexPath = IndexPath(item: 0, section: 0)
|
|
|
-
|
|
|
-
|
|
|
lazy var titleView: TSTitleView = {
|
|
|
let titleView = TSTitleView()
|
|
|
- titleView.titleLab.text = "Ratio".localized
|
|
|
+ titleView.titleLab.text = "Aspect Ratio".localized
|
|
|
return titleView
|
|
|
}()
|
|
|
|
|
@@ -63,20 +64,15 @@ class TSTTPRatioView:TSBaseView {
|
|
|
make.height.equalTo(titleViewH)
|
|
|
}
|
|
|
|
|
|
- currentIndexPath = IndexPath(item: 0, section: 0)
|
|
|
contentView.addSubview(styleCollectionView)
|
|
|
styleCollectionView.snp.makeConstraints { make in
|
|
|
make.top.equalTo(titleView.snp.bottom)
|
|
|
make.leading.trailing.equalTo(0)
|
|
|
- make.height.equalTo(110)
|
|
|
+ make.height.equalTo(itemH)
|
|
|
make.bottom.equalTo(0)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func unCheck(){
|
|
|
- styleCollectionView.deselectItem(at: currentIndexPath, animated: true)
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
extension TSTTPRatioView: UICollectionViewDataSource ,UICollectionViewDelegate {
|
|
@@ -100,7 +96,6 @@ extension TSTTPRatioView: UICollectionViewDataSource ,UICollectionViewDelegate {
|
|
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
if let model = dataArray.safeObj(At: indexPath.item){
|
|
|
- currentIndexPath = indexPath
|
|
|
selectedValueBlock?(model)
|
|
|
}
|
|
|
}
|
|
@@ -116,14 +111,15 @@ class TSTTPRatioViewCell: TSBaseCollectionCell {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var itemModel:TSGenerateStyleModel = TSGenerateStyleModel(){
|
|
|
+ var itemModel:AspectRatio = AspectRatio.ratio9_16{
|
|
|
didSet{
|
|
|
- imageView.image = UIImage(named: itemModel.imageName)
|
|
|
+ imageView.image = UIImage(named: itemModel.ttpImageNamed)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
lazy var boardImageView: UIImageView = {
|
|
|
- let boardImageView = UIImageView.createImageView(imageName: "ttp_selected_border")
|
|
|
+ let boardImageView = UIImageView()
|
|
|
+ boardImageView.cornerRadius = 16
|
|
|
boardImageView.isHidden = true
|
|
|
return boardImageView
|
|
|
}()
|
|
@@ -131,27 +127,30 @@ class TSTTPRatioViewCell: TSBaseCollectionCell {
|
|
|
|
|
|
lazy var imageView: UIImageView = {
|
|
|
let imageView = UIImageView()
|
|
|
- imageView.cornerRadius = 40.0
|
|
|
+ boardImageView.cornerRadius = 16
|
|
|
return imageView
|
|
|
}()
|
|
|
|
|
|
|
|
|
override func creatUI() {
|
|
|
- //cell 100*110
|
|
|
|
|
|
bgContentView.addSubview(imageView)
|
|
|
imageView.snp.makeConstraints { make in
|
|
|
make.top.equalTo(0)
|
|
|
make.centerX.equalToSuperview()
|
|
|
- make.width.height.equalTo(80)
|
|
|
+ make.width.equalTo(itemW)
|
|
|
+ make.height.equalTo(itemH)
|
|
|
}
|
|
|
-
|
|
|
|
|
|
-
|
|
|
imageView.addSubview(boardImageView)
|
|
|
boardImageView.snp.makeConstraints { make in
|
|
|
make.top.bottom.leading.trailing.equalTo(0)
|
|
|
}
|
|
|
+
|
|
|
+ boardImageView.setNeedsLayout()
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ self.boardImageView.addGradientBorder(colors: ["#FA794F".uiColor,"#F8C32A".uiColor,"#FEFBF4".uiColor],width: 1.5,startPoint: CGPoint(x: 0, y: 1),endPoint: CGPoint(x: 1, y: 0))
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|