Как создать собственный компонент, который принимает (и передает) все возможные аргументы TextField?IOS

Программируем под IOS
Ответить
Гость
 Как создать собственный компонент, который принимает (и передает) все возможные аргументы TextField?

Сообщение Гость »


I currently have following custom component that wraps and styles a default TextField from swift ui. I came across an issue where I now need to re-use this where @Binding is no longer just String, but rather, can be a number like int or double, thus underlying TextField needs to change and take in TextField(value: ..., formatter: ...) instead of just text.

I can turn all of the modifiers into a custom modifier and apply it to relevant text fields to apply the styling, but am wondering if there is a solution where I can keep this as a custom component and instead allow TextInputSmall to take in and pass down all possible permutations of TextField arguments, for example

TextInputSmall("", text: $someString) and TextInputSmall("", value: $someNumber, formatter: .number)
struct TextInputSmall: View { // Public Variables var accentColor = Color._orange @Binding var text: String // Private Variables @FocusState private var focused: Bool // Body var body: some View { TextField( "", text: $text ) .font(...) .foregroundStyle(...) .accentColor(...) .focused($focused) .submitLabel(.done) .frame(...) .padding(...) .background(...) } }

Источник: https://stackoverflow.com/questions/780 ... sible-text
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»