Skip to content

Commit 8f1fa6f

Browse files
committed
UIKitBackend: Adjust appearance of menu-style picker; use link color, chevron size
1 parent a24d856 commit 8f1fa6f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Sources/UIKitBackend/UIKitBackend+Picker.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,20 @@ final class UIButtonPicker: WrapperWidget<UIButton>, Picker {
201201
super.init(child: UIButton())
202202

203203
let imageName =
204-
if #available(iOS 18, macCatalyst 18, tvOS 18, visionOS 2, *) {
204+
if #available(iOS 26, macCatalyst 26, tvOS 26, visionOS 2, *) {
205205
"chevron.compact.up.chevron.compact.down"
206206
} else {
207207
"chevron.up.chevron.down"
208208
}
209+
let image = UIImage(systemName: imageName)
209210

210-
child.setImage(UIImage(systemName: imageName), for: .normal)
211-
child.showsMenuAsPrimaryAction = true
211+
child.setImage(image, for: .normal)
212+
child.imageEdgeInsets.left = 2
212213

213214
// Render the chevrons to the right of the text (they render to the left by default)
214215
child.semanticContentAttribute = .forceRightToLeft
216+
217+
child.showsMenuAsPrimaryAction = true
215218
}
216219

217220
func setOptions(to options: [String]) {
@@ -245,7 +248,7 @@ final class UIButtonPicker: WrapperWidget<UIButton>, Picker {
245248
func updateEnvironment(_ environment: EnvironmentValues) {
246249
child.isEnabled = environment.isEnabled
247250

248-
let color = environment.foregroundColor?.resolve(in: environment).uiColor ?? .label
251+
let color = environment.foregroundColor?.resolve(in: environment).uiColor ?? .link
249252
let title = selectedIndex.map { options[$0] } ?? ""
250253

251254
#if os(tvOS)
@@ -255,12 +258,23 @@ final class UIButtonPicker: WrapperWidget<UIButton>, Picker {
255258
UIKitBackend.attributedString(
256259
text: title,
257260
environment: environment,
258-
defaultForegroundColor: .label
261+
defaultForegroundColor: .link
259262
),
260263
for: .normal
261264
)
262265
#endif
263266

267+
// This was obtained experimentally by trying to visually match SwiftUI
268+
let chevronPointSizeScaleFactor = 0.8
269+
let resolvedFont = environment.resolvedFont
270+
let symbolConfiguration = UIImage.SymbolConfiguration(
271+
pointSize: resolvedFont.pointSize * chevronPointSizeScaleFactor
272+
)
273+
child.setPreferredSymbolConfiguration(
274+
symbolConfiguration,
275+
forImageIn: .normal
276+
)
277+
264278
child.tintColor = color
265279

266280
if #available(iOS 16, macCatalyst 16, *) {

0 commit comments

Comments
 (0)