Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

illescasDaniel/CustomizableAlertController

Open more actions menu

Repository files navigation

CustomizableAlertController

Hacking the UIAlertController to fully customize it!

Screenshot

Example

let customAlertController = CustomizableAlertController(title: "Do you want to do X?", message: ":D hii", preferredStyle: .alert)
customAlertController.addAction(title: "Yes", style: .default, image: X)
customAlertController.addAction(title: "Cancel", style: .cancel)

let greenAction = UIAlertAction(title: "I'm green!", style: .default)
customAlertController.addAction(greenAction)

let labelElement = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 20))
labelElement.text = "Hii!!"
labelElement.textColor = .white
greenAction.accessoryView = labelElement

customAlertController.addParallaxEffect(x: 20, y: 20)

self.present(customAlertController, animated: true)

// customAlertController.lazyContentView?.backgroundColor = .red

customAlertController.titleAttributes += [
     StringAttribute(key: .font, value: UIFont.boldSystemFont(ofSize: 17), range: NSRange(location: "Do ".count, length: "you".count)),
    StringAttribute(key: .font, value: UIFont.boldSystemFont(ofSize: 17), range: NSRange(location: "Do you want to do ".count, length: "X".count))
]

customAlertController.messageAttributes += [
    StringAttribute(key: .foregroundColor, value: UIColor.orange, range: NSRange(location: 0, length: 3))
]

greenAction.titleAttributes = [
    StringAttribute(key: .foregroundColor, value: UIColor.green)
]

Medium article

https://medium.com/@Daniel_illescas/hacking-ios-alerts-with-swift-61aefce9736a

About

Hacking the UIAlertController to fully customize it

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.