优化图片预览分段控件样式

This commit is contained in:
2026-08-13 16:11:36 +08:00
parent 48b6b9be22
commit 6e2899dbfd
2 changed files with 34 additions and 6 deletions
@@ -52,6 +52,7 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
private let deleteButton = UIButton(type: .system)
private let refreshButton = UIButton(type: .system)
private var variantControlsHeightConstraint: Constraint?
private var variantSegmentedControlWidthConstraint: Constraint?
private var didConfigureVariantControls = false
private var showsVariantControls = false
private var variantControlsAnimationGeneration = 0
@@ -168,14 +169,13 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
counterContainer.layer.cornerRadius = 17
counterContainer.clipsToBounds = true
variantSegmentedControl.selectedSegmentTintColor = UIColor(white: 0.22, alpha: 1)
variantSegmentedControl.backgroundColor = UIColor(white: 0.065, alpha: 1)
variantSegmentedControl.selectedSegmentTintColor = UIColor.white.withAlphaComponent(0.2)
variantSegmentedControl.setTitleTextAttributes(
[.foregroundColor: UIColor.white.withAlphaComponent(0.62), .font: UIFont.systemFont(ofSize: 15)],
[.foregroundColor: UIColor.white.withAlphaComponent(0.7)],
for: .normal
)
variantSegmentedControl.setTitleTextAttributes(
[.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 15, weight: .semibold)],
[.foregroundColor: UIColor.white],
for: .selected
)
variantSegmentedControl.accessibilityIdentifier = "travelAlbum.previewVariantSegmentedControl"
@@ -258,8 +258,9 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
variantSegmentedControl.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(20)
make.centerY.equalToSuperview()
make.height.equalTo(40)
make.trailing.equalTo(highResolutionButton.snp.leading).offset(-12)
variantSegmentedControlWidthConstraint = make.width.equalTo(124).constraint
make.height.equalTo(32)
make.trailing.lessThanOrEqualTo(highResolutionButton.snp.leading).offset(-12)
}
highResolutionButton.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(18)
@@ -406,6 +407,13 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
for (index, asset) in project.orderedAssets.enumerated() {
variantSegmentedControl.insertSegment(withTitle: asset.kind.title, at: index, animated: false)
}
let controlWidth: CGFloat
switch project.orderedAssets.count {
case 4: controlWidth = 220
case 3: controlWidth = 180
default: controlWidth = 124
}
variantSegmentedControlWidthConstraint?.update(offset: controlWidth)
variantSegmentedControl.selectedSegmentIndex = project.orderedAssets.firstIndex {
$0.kind == activeKind
} ?? 0