Skip to content

Commit 9425918

Browse files
author
Anton Poltoratskyi
authored
Update README.md
1 parent 9a545bd commit 9425918

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

README.md

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,74 @@ Available subspecs:
3232
- `Utils`
3333
- `Alert`
3434

35-
3635
## Usage
3736

38-
![Demo](https://github.com/AntonPoltoratskyi/NativeUI/blob/master/Example/Demo/default.gif)
39-
![Demo](https://github.com/AntonPoltoratskyi/NativeUI/blob/master/Example/Demo/custom.gif)
37+
<img src="https://github.com/AntonPoltoratskyi/NativeUI/blob/master/Example/Demo/default.gif" width="250" /> <img src="https://github.com/AntonPoltoratskyi/NativeUI/blob/master/Example/Demo/custom.gif" width="250" />
38+
39+
**`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)
85+
86+
let customView = CustomView()
87+
customView.translatesAutoresizingMaskIntoConstraints = false
88+
customView.imageView.backgroundColor = .orange
89+
customView.titleLabel.text = "Some text"
90+
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.
40103

41104
## Author
42105

0 commit comments

Comments
 (0)