You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**`AlertViewController` is a customizable replacement for native `UIAlertController`.**
40
+
41
+
Sometimes we need to set NSAttributedString into native alert, but public API doesn't allow it. As a workaroud we could use private API, but in general we should avoid using it.
42
+
43
+
`AlertViewController` looks exactly like native `UIAlertController`, but very configurable.
44
+
45
+
### Configuration
46
+
47
+
1. Default initialization with title, message as `String`.
48
+
49
+
```swift
50
+
let cancelAction = Alert.Action(title: "Cancel", style: .primary)
51
+
let confirmAction = Alert.Action(title: "Confirm", style: .default)
52
+
53
+
let viewModel =Alert(
54
+
title: "Your Title",
55
+
titleFont: ...// your custom title font
56
+
message:"Your Message",
57
+
messageFont: ...// your custom message font
58
+
actions: [cancelAction, confirmAction]
59
+
)
60
+
let alert =AlertViewController(viewModel: viewModel)
61
+
present(alert, animated: true)
62
+
```
63
+
64
+
2. Default initialization with title, message as `NSAttributedString`
65
+
66
+
```swift
67
+
let cancelAction = Alert.Action(title: "Cancel", style: .primary)
68
+
let confirmAction = Alert.Action(title: "Confirm", style: .default)
69
+
70
+
let viewModel =Alert(
71
+
title: ...// your title (NSAttributedString)
72
+
message:...// your message (NSAttributedString)
73
+
actions: [cancelAction, confirmAction]
74
+
)
75
+
let alert =AlertViewController(viewModel: viewModel)
76
+
present(alert, animated: true)
77
+
```
78
+
79
+
3. Initialization with title, message and custom `UIView` object as content view to implement complex layout.
80
+
81
+
82
+
```swift
83
+
let cancelAction = Alert.Action(title: "Cancel", style: .primary)
84
+
let confirmAction = Alert.Action(title: "Confirm", style: .default)
customView.subtitleLabel.text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
91
+
92
+
let viewModel =Alert(
93
+
title: "Your Title",
94
+
message: nil,
95
+
contentView: customView,
96
+
actions: [cancelAction, confirmAction]
97
+
)
98
+
let alert =AlertViewController(viewModel: viewModel)
99
+
present(alert, animated: true)
100
+
```
101
+
102
+
See [Alert.swift](https://github.com/AntonPoltoratskyi/NativeUI/blob/master/NativeUI/Sources/Alert/Alert.swift) for more details.
0 commit comments