英文:
Trying to identify an element on Apple Guideline website for use with Swift
问题
这个元素看起来是一个用于选择两个选项("daily Notification Avg" 或 "A to Z")的选择器。
英文:
I was accessing one of the Apple websites about Pickers. The site below:
I was interessed to use the Picker below, but I can't identify what type of element is that.
It appears to be an element to choose between two options("daily Notification Avg" or "A to Z").
What is the element/object ?
答案1
得分: 1
SwiftUI
您可以使用带有segmented
样式的picker
struct ContentView: View {
@State private var selected = 0
var body: some View {
VStack {
Picker("", selection: $selected) {
Text("每日通知平均").tag(0)
Text("A到Z").tag(1)
}
.pickerStyle(.segmented)
}
}
}
UIKit
segmentedControl = UISegmentedControl(items: ["每日通知平均", "A到Z"])
segmentedControl.frame = CGRect(x: 60, y: 250, width: 200, height: 30)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: #selector(segmentedControlAction(_:)), for: .valueChanged)
view.addSubview(segmentedControl)
英文:
SwiftUI
You can use a picker
with segmented
style
struct ContentView: View {
@State private var selected = 0
var body: some View {
VStack {
Picker("", selection: $selected) {
Text("Daily Notification Avg").tag(0)
Text("A to Z").tag(1)
}
.pickerStyle(.segmented)
}
}
}
UIKit
segmentedControl = UISegmentedControl (items: ["Daily Notification Avg","A to Z"])
segmentedControl.frame = CGRectMake(60, 250,200, 30)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: #selector(segmentedControlAction(_)), forControlEvents: .ValueChanged)
view.addSubview(segmentedControl)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论