{"id":18839747,"url":"https://github.com/maximbilan/uialertcontroller-customization","last_synced_at":"2025-04-14T07:03:22.537Z","repository":{"id":76126339,"uuid":"51917232","full_name":"maximbilan/UIAlertController-Customization","owner":"maximbilan","description":"Customization of UIAlertController","archived":false,"fork":false,"pushed_at":"2018-09-22T09:42:47.000Z","size":344,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T20:44:26.536Z","etag":null,"topics":["ios","swift","tutorial","ui","ui-components","uialertaction","uialertcontroller","uialertcontroller-customization","uikit"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximbilan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-17T11:19:43.000Z","updated_at":"2021-12-20T23:42:10.000Z","dependencies_parsed_at":"2023-02-27T01:01:14.563Z","dependency_job_id":null,"html_url":"https://github.com/maximbilan/UIAlertController-Customization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FUIAlertController-Customization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FUIAlertController-Customization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FUIAlertController-Customization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FUIAlertController-Customization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximbilan","download_url":"https://codeload.github.com/maximbilan/UIAlertController-Customization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837285,"owners_count":21169374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","swift","tutorial","ui","ui-components","uialertaction","uialertcontroller","uialertcontroller-customization","uikit"],"created_at":"2024-11-08T02:43:57.993Z","updated_at":"2025-04-14T07:03:22.528Z","avatar_url":"https://github.com/maximbilan.png","language":"Swift","readme":"# Customization of UIAlertController\n\nRecently I’m faced with an unusual task using \u003ca href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/\"\u003eUIAlertController\u003c/a\u003e. First, add an image to some of items. And the second, add \u003ca href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISwitch_Class/\"\u003eUISwitch\u003c/a\u003e control.\n\n![alt tag](https://raw.github.com/maximbilan/UIAlertController-Customization/master/img/1.png)\n\nI know it doesn’t matсh \u003ci\u003eApple\u003c/i\u003e design flow, but maybe someone will come in handy for resolving different tasks.\n\nThe first, how to add an image. \u003ca href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/\"\u003eUIAlertController\u003c/a\u003e or \u003ca href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertAction_Class/\"\u003eUIAlertAction\u003c/a\u003e has not public methods for this, but you can do this via \u003ci\u003esetValue\u003c/i\u003e for key ‘\u003ci\u003eimage\u003c/i\u003e’. For example:\n\n\u003cpre\u003e\nalertAction.setValue(UIImage(named: \"image1.png\"), forKey: \"image\")\n\u003c/pre\u003e\n\nBut you will get no good result.\n\n![alt tag](https://raw.github.com/maximbilan/UIAlertController-Customization/master/img/2.png)\n\nPlease create a version of this image with the specified rendering mode. In our case with \u003ci\u003eAlwaysOriginal\u003c/i\u003e.\n\n\u003cpre\u003e\nalertAction.setValue(UIImage(named: \"image1.png\")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), forKey: \"image\")\n\u003c/pre\u003e\n\nAnd see what we will get:\n\n![alt tag](https://raw.github.com/maximbilan/UIAlertController-Customization/master/img/3.png)\n\nThe second thing, how to add a switch control? \n\nLet’s create a new view controller and a user interface for this.\n\n![alt tag](https://raw.github.com/maximbilan/UIAlertController-Customization/master/img/4.png)\n\n\u003cpre\u003e\nimport UIKit\n\nclass SwitchAlertActionViewController: UIViewController {\n  @IBOutlet weak var valueSwitch: UISwitch!\n  var isSwitchOn = false\n \n  override func viewDidLoad() {\n    super.viewDidLoad()\n\n    valueSwitch.on = isSwitchOn\n  }\n}\n\u003c/pre\u003e\n\nAnd the last point, we need to apply this controller to \u003ca href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertAction_Class/\"\u003eUIAlertAction\u003c/a\u003e. The same way using a key \u003cb\u003e\u003ci\u003econtentViewController\u003c/i\u003e\u003c/b\u003e.\n\n\u003cpre\u003e\nlet switchAlert = SwitchAlertActionViewController()\nswitchAlert.isSwitchOn = true\nalertAction.setValue(switchAlert, forKey: \"contentViewController\")\n\u003c/pre\u003e\n\n![alt tag](https://raw.github.com/maximbilan/UIAlertController-Customization/master/img/5.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximbilan%2Fuialertcontroller-customization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximbilan%2Fuialertcontroller-customization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximbilan%2Fuialertcontroller-customization/lists"}