我想知道如何仅将文本的一部分设为粗体,同时在 SwiftUI 中保持其余部分“常规”。
我目前有:
Text("Coronavirus Disease of 2019")
Run Code Online (Sandbox Code Playgroud)
我希望它打印出来CO罗纳六RUS d isease的20 19和一直没能得到的只有一些地方大胆。
我希望能够向 AlertButton 添加图标和文本,但类型是类型 Text?
struct NavigationAddItem: View {
@State var showActionView = true
var actionSheet: ActionSheet {
ActionSheet(title: Text("Select an action"), message: nil, buttons: [
.default(Text("Option A"), action: {
// TODO: Enter Option A action
}),
.default(Text("Option B"), action: {
// TODO: Enter Option B action
}),
.cancel()
])
}
var body: some View {
Button(action: {
self.showActionView.toggle()
}) {
Image(systemName: "plus")
.font(.system(size: 24))
}
.actionSheet(isPresented: $showActionView, content: {
self.actionSheet
})
}
}
struct NavigationItems_Previews: PreviewProvider {
static var previews: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作可单独移动的对象。我能够为一个对象成功完成此操作,但是一旦将其放入数组中,这些对象将无法再移动。
模型:
class SocialStore: ObservableObject {
@Published var socials : [Social]
init(socials: [Social]){
self.socials = socials
}
}
class Social : ObservableObject{
var id: Int
var imageName: String
var companyName: String
@Published var pos: CGPoint
init(id: Int, imageName: String, companyName: String, pos: CGPoint) {
self.id = id
self.imageName = imageName
self.companyName = companyName
self.pos = pos
}
var dragGesture : some Gesture {
DragGesture()
.onChanged { value in
self.pos = value.location
print(self.pos)
}
}
}
Run Code Online (Sandbox Code Playgroud)
多张图片(不跟随拖动的图片):
struct ContentView : View …
Run Code Online (Sandbox Code Playgroud) 当步进器的值为零时,我想禁用一半的步进器。
我在步进器上尝试了 .disabled 函数,但它禁用了整个步进器,我只想禁用步进器的递减部分。
struct StepperLabelView : View {
@ObservedObject var social: Social
var body: some View {
VStack {
Stepper(onIncrement: {
self.social.quantity += 1
socialsInCanvas += [Social(companyName: self.social.companyName)]
}, onDecrement: {
self.social.quantity -= 1
socialsInCanvas.removeLast()
}, label: { Text("") })
.disabled(social.quantity == 0)
}
.padding()
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试更改 TextFormField 前缀图标位置,但我不明白该怎么做,任何人都知道我使用的代码如下
child: TextFormField(
autocorrect: false,
maxLines: 4,
decoration: InputDecoration(
border: new OutlineInputBorder(
borderSide: new BorderSide(
style: BorderStyle.solid)),
hintStyle: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.1)),
prefixIcon: Icon(Icons.edit),
hintText: "Onion 1kg",
labelText: 'Item Description (Optional)',
),
style: TextStyle(
color: Color.fromRGBO(25, 25, 35, 1),
fontSize:18,
),
)
Run Code Online (Sandbox Code Playgroud)