English 中文(简体)
快速情报和安全局 皮尔克文的涂 The不可行
原标题:SwiftUI Picker: The padding of content in Picker does not work

是否在采集器中有任何“pa”内容? 例如文本(......)。

Picker(selection: $picked) {
    ForEach(0...10, id: .self) { num in
        Text("(num)").tag("(num)")
            .font(.system(size: 30))
            .foregroundColor(pickedMinute == "(num)" ? .blue : .black)
            .padding(20) //  ***It does not work***
    }
} label: {
    Text("picker")
}
最佳回答

does work is the .font modifier. 并且还有<代码>。 结合使用,你可以有更大的体,有更大的间隔:

Picker(selection: $picked) {
    ForEach(0...10, id: .self) { num in
        Text("(num)").tag("(num)")
            .font(.system(size: 15))
            .foregroundColor(pickedMinute == "(num)" ? .blue : .black)
    }
} label: {
    Text("picker")
}
.pickerStyle(.wheel)
.scaleEffect(2)

Screenshot

问题回答

Picker in SwiftUI does not support padding, you can create a custom Picker with padding like the following:

ScrollView(.horizontal, showsIndicators: false) {
    HStack {
        ForEach(numbers, id: .self) { number in
            Text("(number)")
                .font(.system(size: 30))
                .foregroundColor(self.pickedNumber == number ? .blue : .black)
                .padding(20)
                .onTapGesture {
                    self.pickedNumber = number
                }
        }
    }
}




相关问题
Can the struct padding be safely used by the user code?

Assuming I have a struct like the following: struct Struct { char Char; int Int; }; and sizeof( int ) is greater than one and the compiler adds padding for the Char member variable - is the ...

String padding in tsql

I print out a bunch of DDL statements that are dynamically created and want to align the output in a specific way. PRINT ALTER TABLE + @TableName + WITH NOCHECK ADD CONSTRAINT CK_ + @TableName +...

Can t achieve padding in menu items using sIFR 3

n00b question alert, but I ve been struggling for a few days with this one and have searched in vain for the solution in other posts! I have a horizontal menu that has padding either side of the text ...

Extra padding in <input type="text">

It seems that every browser adds some magic hardcoded padding inside <input type="text">. Some browsers (IE, Safari, Chrome) make the input box a bit taller, but they properly top align as if it ...

Setting Padding - why it says padding.all is not variable?

I do not understand why there is Control.padding.all which is int and according to hint there is set as well as get but I cannot set it (Control.Padding.All=5)? I would be grateful for explanation. ...

Python tabstop-aware len() and padding functions

Python s len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat like any other single-width character, and don t round len() up to the nearest multiple of tabstop. ...

热门标签