{"id":13465434,"url":"https://github.com/dqhieu/UIGradient","last_synced_at":"2025-03-25T16:31:44.539Z","repository":{"id":47595619,"uuid":"113425264","full_name":"dqhieu/UIGradient","owner":"dqhieu","description":"A simple and powerful library for using gradient layer, image, color","archived":false,"fork":false,"pushed_at":"2023-10-01T00:21:09.000Z","size":2882,"stargazers_count":270,"open_issues_count":5,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-25T09:23:57.990Z","etag":null,"topics":["color","colorful","gradient","gradient-colors","gradient-image","gradientlayer","ios","ios-lib","ios-swift","swift","uigradient"],"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/dqhieu.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}},"created_at":"2017-12-07T08:46:31.000Z","updated_at":"2025-03-10T06:05:21.000Z","dependencies_parsed_at":"2022-07-26T15:45:13.352Z","dependency_job_id":"f7310c2e-c96f-4313-ba58-e3bb1c61ea40","html_url":"https://github.com/dqhieu/UIGradient","commit_stats":{"total_commits":37,"total_committers":6,"mean_commits":6.166666666666667,"dds":0.5405405405405406,"last_synced_commit":"7cddd16f9e48f8243033d22a5d5d3119d6473ddb"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqhieu%2FUIGradient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqhieu%2FUIGradient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqhieu%2FUIGradient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dqhieu%2FUIGradient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dqhieu","download_url":"https://codeload.github.com/dqhieu/UIGradient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245500247,"owners_count":20625532,"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":["color","colorful","gradient","gradient-colors","gradient-image","gradientlayer","ios","ios-lib","ios-swift","swift","uigradient"],"created_at":"2024-07-31T15:00:29.798Z","updated_at":"2025-03-25T16:31:44.036Z","avatar_url":"https://github.com/dqhieu.png","language":"Swift","funding_links":[],"categories":["Libs","Colors [🔝](#readme)","Swift"],"sub_categories":["Colors"],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/dqhieu/UIGradient\"\u003e\u003cimg src=\"Images/UIGradient.png\" width=\"300\" /\u003e\u003c/a\u003e\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/dqhieu/UIGradient\"\u003e\u003cimg src=\"Images/UIGradientExample.png\" width=\"300\" /\u003e\u003c/a\u003e\n\n\n![Platform](https://img.shields.io/cocoapods/p/UIGradient.svg?style=flat) ![Swift 5](https://img.shields.io/badge/Swift-5-orange.svg) ![Version](https://img.shields.io/cocoapods/v/UIGradient.svg?style=flat) ![License](https://img.shields.io/cocoapods/l/UIGradient.svg?style=flat)\n\u003c/p\u003e\n\n## Installation\n### SPM\nAdd `https://github.com/dqhieu/UIGradient.git` to Swift Package Manager tab in Xcode\n### Cocoapods\nAdd `pod 'UIGradient'` to your Podfile\n\n## Usage\n### GradientLayer\nCreate a GradientLayer then add it to your view's\n```swift\npublic extension UIView {\n\n    func addGradientWithDirection(_ direction: GradientDirection, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil)\n\n    func addGradient(_ gradientLayer: GradientLayer, cornerRadius: CGFloat = 0)\n\t\n}\n```\nExample\n```swift\nlet gradient = GradientLayer(direction: GradientDirection, colors: [UIColor])\nview.addGradient(gradient)\n```\nUIGradient supports those directions below:\n```swift\npublic enum GradientDirection {\n    case topToBottom // top to bottom\n    case bottomToTop // bottom to top\n    case leftToRight // left to right\n    case rightToLeft // right to left\n    case topLeftToBottomRight // top left to bottom right\n    case topRightToBottomLeft // top right to bottom left\n    case bottomLeftToTopRight // bottom left to top right\n    case bottomRightToTopLeft // bottom right to top left\n}\n```\n\nYou can also create a GradientLayer clone instance using this function:\n```swift\nopen class GradientLayer: CAGradientLayer {\n    ...\n    public final func clone() -\u003e GradientLayer\n    ...\n}\n```\n\n### Gradient color\nUIGradient allows you create gradient color\n```swift\npublic extension UIColor {\n\n    static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -\u003e UIColor?\n\t\n    static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -\u003e UIColor?\n\t\n}\n```\nExample\n```swift\nlet view1 = UIView(frame: frame)\nview1.backgroundColor = UIColor.fromGradientWithDirection(.topToBottom, frame: frame, colors: [UIColor.blue, UIColor.green])\n//view1.backgroundColor = UIColor.fromGradient(gradient, frame: frame)\n```\n```swift\nlet label = UILabel(frame: frame)\nlabel.text = \"some text\"\nlabel.textColor = UIColor.fromGradient(gradient, frame: frame)\n```\n\n### Gradient image\nUIGradient also allows you create gradient image\n```swift\npublic extension UIImage {\n\n    static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -\u003e UIImage?\n\t\n    static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -\u003e UIImage?\n\t\n}\n```\nExample\n```swift\nlet imageView = UIImageView(frame: frame)\nimageView.image = UIImage.fromGradientWithDirection(.bottomLeftToTopRight, frame: frame, colors: [UIColor.blue, UIColor.green])\n```\n\n## Gradient library\nUIGradient was inspired by [@lukedesigner](https://twitter.com/lukedesigner). I created 24 gradients based on his [website](http://www.gradients.io) and make them static variables of GradientLayer so everyone can use those gradients for their projects.\n```swift\nlet oceanBlueGradient \t\t= GradientLayer.oceanBlue\nlet sanguineGradient  \t\t= GradientLayer.sanguine\nlet lusciousLimeGradient \t= GradientLayer.lusciousLime\nlet purpleLakeGradient \t\t= GradientLayer.purpleLake\n...\n```\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"Images/OceanBlue.png\" width=\"200\" /\u003e\u003cimg src=\"Images/Sanguine.png\" width=\"200\" /\u003e\u003cimg src=\"Images/LusciousLime.png\" width=\"200\" /\u003e\u003cimg src=\"Images/PurpleLake.png\" width=\"200\" /\u003e\n\u003c/p\u003e\nYou can explore them in my example project.\n\n## Author\nUIGradient was created by **Đinh Quang Hiếu** in 2017 using Swift. If you found any problem please create issue or pull request to help me improve this open source project. Thanks!\n\n## License\nUIGradient is released and distributed under the terms and conditions of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqhieu%2FUIGradient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdqhieu%2FUIGradient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdqhieu%2FUIGradient/lists"}