如何去除SwiftUI Picker组件中的^标记?
移除SwiftUI Picker默认的下拉箭头(^标记)
针对你的代码,提供两种适配不同iOS版本的解决方案:
方案一:iOS 16+ 直接隐藏指示器
利用iOS 16新增的API,直接隐藏Picker菜单的默认箭头:
Button(action: {}) { ZStack { Picker("", selection: $month){ ForEach(0..<months.count, id: \.self) { index in Text("\(months[index])") } } .accentColor(.black) .padding(.trailing, 30) .tag(3) .pickerStyle(.menu) .menuIndicatorVisibility(.hidden) // 隐藏默认箭头 Image("bul_drop_down").position(x: 75, y: 26) } }.buttonStyle(SelectBtnStyle(width: 100))
方案二:兼容iOS 15及以下,通过裁剪隐藏箭头
如果需要适配更低版本,可通过缩小Picker的显示范围并裁剪,把默认箭头隐藏:
Button(action: {}) { ZStack { Picker("", selection: $month){ ForEach(0..<months.count, id: \.self) { index in Text("\(months[index])") } } .accentColor(.black) .padding(.trailing, 30) .tag(3) .frame(width: 80) // 限制宽度,裁剪掉右侧箭头区域 .clipped() Image("bul_drop_down").position(x: 75, y: 26) } }.buttonStyle(SelectBtnStyle(width: 100))
内容的提问来源于stack exchange,提问作者nickpury_hwang
相关产品推荐
相关产品推荐

