SwiftUI Textfield NumberFomatter、NumberFormatter.Style.decimal

Styleはinitで渡せない為、派生クラス作成。

派生クラス

class DecimanNumberFormatter : NumberFormatter {
    override init() {
        super.init()
        self.numberStyle = .decimal
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

使う側

TextField(value: self.$input, formatter: DecimanNumberFormatter(), prompt: Text("Number"), label: {
    Label(self.title, systemImage: self.systemImage)
})

SwiftSwift,SwiftUI

Posted by shi-n