尝试在苹果指南网站上识别一个用于Swift的元素。

huangapple go评论69阅读模式
英文:

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:

https://developer.apple.com/design/human-interface-guidelines/components/selection-and-input/pickers/

I was interessed to use the Picker below, but I can't identify what type of element is that.

尝试在苹果指南网站上识别一个用于Swift的元素。

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)

huangapple
  • 本文由 发表于 2023年4月17日 21:07:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035494-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定