{"id":24123808,"url":"https://github.com/chrs1885/wcag-colors","last_synced_at":"2025-09-18T13:32:09.968Z","repository":{"id":56926236,"uuid":"387887723","full_name":"chrs1885/WCAG-Colors","owner":"chrs1885","description":"Apple framework for calculating color contrast ratios, WCAG conformance, and high contrast color values (UIColor \u0026 NSColor).","archived":false,"fork":false,"pushed_at":"2023-11-20T22:31:17.000Z","size":445,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-01-11T13:18:04.323Z","etag":null,"topics":["a11y","accessibility","accessibility-checker","colors","contrast-ratio","ios","macos","nscolor","swift","uicolor","wcag"],"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/chrs1885.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-07-20T18:59:32.000Z","updated_at":"2025-01-10T17:26:02.000Z","dependencies_parsed_at":"2023-11-20T20:01:15.811Z","dependency_job_id":null,"html_url":"https://github.com/chrs1885/WCAG-Colors","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"085adb26e4c51bd8faef1f9ddb78be97faab2be4"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrs1885%2FWCAG-Colors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrs1885%2FWCAG-Colors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrs1885%2FWCAG-Colors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrs1885%2FWCAG-Colors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrs1885","download_url":"https://codeload.github.com/chrs1885/WCAG-Colors/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233484537,"owners_count":18683099,"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":["a11y","accessibility","accessibility-checker","colors","contrast-ratio","ios","macos","nscolor","swift","uicolor","wcag"],"created_at":"2025-01-11T13:18:16.826Z","updated_at":"2025-09-18T13:32:04.646Z","avatar_url":"https://github.com/chrs1885.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](https://user-images.githubusercontent.com/1390908/133853563-3daef365-e890-41d2-ba6e-68cc9f17cd90.png)\n\n[![Version](https://img.shields.io/cocoapods/v/WCAG-Colors.svg?style=flat)](https://cocoapods.org/pods/WCAG-Colors)\n[![License](https://img.shields.io/cocoapods/l/WCAG-Colors.svg?style=flat)](https://cocoapods.org/pods/WCAG-Colors)\n[![Platform](https://img.shields.io/cocoapods/p/WCAG-Colors.svg?style=flat)](https://cocoapods.org/pods/WCAG-Colors)\n[![Twitter](https://img.shields.io/badge/twitter-%40chr__wendt-58a1f2.svg)](https://twitter.com/chr_wendt)\n\nThe *Web Content Accessibility Guidelines* (WCAG) define minimum contrast ratios for a text and its background. The WCAG-Colors framework extends `UIColor` and `NSColor` with functionality to use WCAG conformant colors within your apps to help people with visual disabilities to perceive content. \n\nIt provides APIs for calculating:\n\n* high contrast text color for a given background color\n* high contrast background color for a given text color\n* high contrast captions colot for a given background image\n* WCAG conformance levels\n* contrast ratios\n\n\nInternally, the provided colors will be mapped to an equivalent of the sRGB color space. All functions will return `nil` and log warnings] with further info in case any input color couldn't be converted. Also note that semi-transparent text colors will be blended with its background color. However, the alpha value of semi-transparent background colors will be ignored since the underlying color can't be determined.**\n\n## Documentation\n\nWCAG-Colors offers a whole lot of features along with a bunch of configurations. To find more about how to use them inside the [documentation](Documentation/Reference/README.md) section.\n\n## Installation\n\nThere are currently three different ways to integrate WCAG-Colors into your apps.\n\n### CocoaPods\n\n```ruby\nuse_frameworks!\n\ntarget 'MyApp' do\n  pod 'WCAG-Colors'\nend\n```\n\n### Swift Package Manager\n\n```ruby\ndependencies: [\n    .package(url: \"https://github.com/chrs1885/WCAG-Colors.git\", from: \"1.0.0\")\n]\n```\n\n### Manually\n\nSimply drop the extension files into your project.\n\n## Usage\n\n\u003ca id=\"colors\"\u003e\u003c/a\u003e \n\n#### Text colors\nGet a high contrast text color for a given background color as follows:\n\n```swift\nlet textColor = UIColor.getTextColor(onBackgroundColor: UIColor.red)!\n```\n\nThis will return the text color with the highest possible contrast (black/white). Alternatively, you can define a list of possible text colors as well as a required conformance level. Since the WCAG requirements for contrast differ in text size and weight, you also need to provide the font used for the text. The following will return the first text color that satisfies the required conformance level (*AA* by default).\n\n```swift\nlet textColor = UIColor.getTextColor(\n    fromColors: [UIColor.red, UIColor.yellow],\n    withFont: myLabel.font,\n    onBackgroundColor: view.backgroundColor,\n    conformanceLevel: .AA\n)!\n```\n\n#### Background colors\n\nThis will also work the other way round. If you are looking for a high contrast background color:\n\n```swift\nlet backgroundColor = UIColor.getBackgroundColor(forTextColor: UIColor.red)!\n\n// or\n\nlet backgroundColor = UIColor.getBackgroundColor(\n    fromColors: [UIColor.red, UIColor.yellow],\n    forTextColor: myLabel.textColor,\n    withFont: myLabel.font,\n    conformanceLevel: .AA\n)!\n```\n\n\u003ca id=\"captions\"\u003e\u003c/a\u003e \n#### Image captions (iOS/tvOS/macOS)\n\nGet a high contrast text color for any given background image as follows:\n\n```swift\nlet textColor = UIColor.getTextColor(onBackgroundImage: myImage imageArea: .full)!\n```\n\nThis will return the text color with the highest possible contrast (black/white) for a specific image area. \n\nAlternatively, you can define a list of possible text colors as well as a required conformance level. Since the WCAG requirements for contrast differ in text size and weight, you also need to provide the font used for the text. The following will return the first text color that satisfies the required conformance level (*AA* by default).\n\n```swift\nlet textColor = UIColor.getTextColor(\n    fromColors: [UIColor.red, UIColor.yellow],\n    withFont: myLabel.font,\n    onBackgroundImage: view.backgroundColor,\n    imageArea: topLeft,\n    conformanceLevel: .AA\n)!\n```\n\nYou can find an overview of all image areas available in the [documentation](Documentation/Reference/enums/ImageArea.md).\n\n#### Calculating contrast ratios \u0026 WCAG conformance levels\n\nThe contrast ratio of two opaque colors can be calculated as well:\n\n```swift\nlet contrastRatio: CGFloat = UIColor.getContrastRatio(forTextColor: UIColor.red, onBackgroundColor: UIColor.yellow)!\n```\n\nOnce the contrast ratio has been determined, you can check the resulting conformance level specified by WCAG as follows:\n\n```swift\nlet passedConformanceLevel = ConformanceLevel(contrastRatio: contrastRatio, fontSize: myLabel.font.pointSize, isBoldFont: true)\n```\n\nHere's an overview of available conformance levels:\n\n| Level   | Contrast ratio                 | Font size               |\n| --------|:-------------------------------|:------------------------|\n| .A      | *Not specified for text color* | -                       |\n| .AA     | 3.0                            | 18.0 (or 14.0 and bold) |\n|         | 4.5                            | 14.0                    |\n| .AAA    | 4.5                            | 18.0 (or 14.0 and bold) |\n| .AAA    | 7.0                            | 14.0                    |\n| .failed | *.AA/.AAA not satisfied*       | -                       |\n\n## Author\n\nchrs1885, chrs1885@gmail.com\n\n## Contributions\n\nWe'd love to see you contributing to this project by proposing or adding features, reporting bugs, or spreading the word. Please have a quick look at our [contribution guidelines](./.github/CONTRIBUTING.md).\n\n## License\n\nWCAG-Colors is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrs1885%2Fwcag-colors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrs1885%2Fwcag-colors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrs1885%2Fwcag-colors/lists"}