I want to be able to add an icon and text to the AlertButton but the type is a type 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: some View {
NavigationAddItem(showActionView: true)
}
}
This code gives the the action sheet but I want to add a image to the left of the text.


I don't think that it is currently possible to define your own View for the Button in an ActionSheet.
Looking at the code for the
ActionSheetwe see the following:This shows that the
Buttonthat theActionSheetuses is typealiased toAlert.ButtonIf we look at the the struct for
Alertwe can see the following methods:Notice that each of the functions that create
Alert.Button, they are:default,cancelanddestructive, only take a label of typeTextand anactionof type(() -> Void)?. This means that you can only pass a view that conforms toText.So trying to pass a view that doesn't conform to
Textwon't work, as you have already discovered.