Я не думаю, что в настоящее время возможно определить ваше собственное представление для кнопки в ActionSheet.
Глядя на код для ActionSheet
, мы видим следующее:
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@available(OSX, unavailable)
public struct ActionSheet {
/// Creates an action sheet with the provided buttons.
public init(title: Text, message: Text? = nil, buttons: [ActionSheet.Button] = [.cancel()])
/// A button representing an operation of an action sheet presentation.
public typealias Button = Alert.Button
}
Это показывает, что Button
, который использует ActionSheet
, типизируется в Alert.Button
Если мы посмотрим на структуру для Alert
, мы увидим следующие методы:
/// A storage type for an alert presentation.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public struct Alert {
/// Creates an alert with one button.
public init(title: Text, message: Text? = nil, dismissButton: Alert.Button? = nil)
/// Creates an alert with two buttons.
///
/// - Note: the system determines the visual ordering of the buttons.
public init(title: Text, message: Text? = nil, primaryButton: Alert.Button, secondaryButton: Alert.Button)
/// A button representing an operation of an alert presentation.
public struct Button {
/// Creates an `Alert.Button` with the default style.
public static func `default`(_ label: Text, action: (() -> Void)? = {}) -> Alert.Button
/// Creates an `Alert.Button` that indicates cancellation of some
/// operation.
public static func cancel(_ label: Text, action: (() -> Void)? = {}) -> Alert.Button
/// Creates an `Alert.Button` that indicates cancellation of some
/// operation.
///
/// - Note: the label of the button is automatically chosen by the
/// system for the appropriate locale.
public static func cancel(_ action: (() -> Void)? = {}) -> Alert.Button
/// Creates an `Alert.Button` with a style indicating destruction of
/// some data.
public static func destructive(_ label: Text, action: (() -> Void)? = {}) -> Alert.Button
}
}
Обратите внимание, что каждая из функций, которые создают Alert.Button
, это: default
, cancel
и destructive
, принимают только метки типа Text
и action
типа (() -> Void)?
. Это означает, что вы можете передать только представление, которое соответствует Text
.
Так что попытка передать представление, которое не соответствует Text
, не будет работать, как вы уже обнаружили.