-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0022d0
commit 06a6b1d
Showing
8 changed files
with
73 additions
and
39 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
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
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
56 changes: 56 additions & 0 deletions
56
Zotero/Scenes/Detail/Annotation Popover/Views/SegmentedControlCell.swift
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,56 @@ | ||
// | ||
// SegmentedControlCell.swift | ||
// Zotero | ||
// | ||
// Created by Michal Rentka on 14.01.2025. | ||
// Copyright © 2025 Corporation for Digital Scholarship. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class SegmentedControlCell: UITableViewCell { | ||
private weak var segmentedControl: UISegmentedControl? | ||
|
||
private var selectionChanged: ((Int) -> Void)? | ||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
setup() | ||
selectionStyle = .none | ||
|
||
func setup() { | ||
let segmentedControl = UISegmentedControl() | ||
segmentedControl.addAction(UIAction(handler: { [weak self] _ in | ||
self?.selectionChanged?(self?.segmentedControl?.selectedSegmentIndex ?? 0) | ||
}), for: .valueChanged) | ||
segmentedControl.translatesAutoresizingMaskIntoConstraints = false | ||
contentView.addSubview(segmentedControl) | ||
self.segmentedControl = segmentedControl | ||
|
||
NSLayoutConstraint.activate([ | ||
segmentedControl.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8), | ||
contentView.bottomAnchor.constraint(equalTo: segmentedControl.bottomAnchor, constant: 8), | ||
segmentedControl.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15), | ||
contentView.trailingAnchor.constraint(equalTo: segmentedControl.trailingAnchor, constant: 15) | ||
]) | ||
} | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
selectionChanged = nil | ||
} | ||
|
||
func setup(selected: Int, segments: [String], selectionChanged: @escaping (Int) -> Void) { | ||
self.selectionChanged = selectionChanged | ||
segmentedControl?.removeAllSegments() | ||
for (idx, segment) in segments.enumerated() { | ||
segmentedControl?.insertSegment(withTitle: segment, at: idx, animated: false) | ||
} | ||
segmentedControl?.selectedSegmentIndex = selected < segments.count ? selected : 0 | ||
} | ||
} |
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