{"id":13672657,"url":"https://github.com/hite/SwiftUI-CSS","last_synced_at":"2025-04-27T22:32:33.772Z","repository":{"id":35457186,"uuid":"205521330","full_name":"hite/SwiftUI-CSS","owner":"hite","description":"A CSS-like style library for SwiftUI.","archived":false,"fork":false,"pushed_at":"2023-02-17T02:01:41.000Z","size":105,"stargazers_count":132,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-11T10:42:36.601Z","etag":null,"topics":["css","style"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hite.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-08-31T09:03:29.000Z","updated_at":"2024-11-06T09:46:18.000Z","dependencies_parsed_at":"2024-01-17T04:18:27.988Z","dependency_job_id":null,"html_url":"https://github.com/hite/SwiftUI-CSS","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hite%2FSwiftUI-CSS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hite%2FSwiftUI-CSS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hite%2FSwiftUI-CSS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hite%2FSwiftUI-CSS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hite","download_url":"https://codeload.github.com/hite/SwiftUI-CSS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251219600,"owners_count":21554444,"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":["css","style"],"created_at":"2024-08-02T09:01:43.236Z","updated_at":"2025-04-27T22:32:32.049Z","avatar_url":"https://github.com/hite.png","language":"Swift","readme":"#  The missing CSS-like module for SwiftUI\n\u003e Check out the [example project using SwiftUI-CSS](https://github.com/hite/SwiftUI-CSS_example);\n\u003e Also, Swift Package availble which url is `https://github.com/hite/SwiftUI-CSS`\n\u003e Supported macOS(.v10_14), .iOS(.v13)\nThe SwiftUI is a great UI development framework for the iOS app. After I wrote some to-be-released app with SwiftUI framework, I realized that I need a solution to write more clear, simple, view-style-decoupled code with lots of custom style design.\n\nSo here is **SwiftUI-CSS**. With **SwiftUI-CSS**, you can:\n\n## 1. write View-style-decoupled codes\n*View-style-decoupled* makes your source code more clear to read, easy to refactor like html with CSS support.\n\n### Without SwifUI-CSS:\n\nThe codes to define View Structure blend into style-defined codes.\n\n``` swift\n             Image(\"image-swift\")\n                 .resizable()\n                 .scaledToFit()\n                 .frame(width:100, height:100)\n                 .cornerRadius(10)\n                 .padding(EdgeInsets(top: 10, leading: 0, bottom: 15, trailing: 0))\n\n              Text(\"Swift\")\n                 .font(.headline)\n                 .foregroundColor(Color(red: 0x33/0xff, green: 0x33/0xff, blue: 0x33/0xff))\n                 .padding(.bottom, 10)\n\n \n              Text(\"Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, Linux, and z/OS. \")\n                 .font(.footnote)\n                 .padding(.horizontal, 10)\n                 .foregroundColor(NormalDescColor)\n                 .lineSpacing(2)\n                 .frame(minHeight: 100, maxHeight: .infinity)\n```\n### With SwifUI-CSS:\n\n1. We divide the previous into two parts. The first part is view structures with class name:\n\n``` swift\n            Image(\"image-swift\")\n                .resizable()\n                .scaledToFit()\n                .addClassName(languageLogo_clsName)\n  \n            Text(\"Swift\")\n                .addClassName(languageTitle_clsName)\n            \n     \n            Text(\"Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, Linux, and z/OS. \")\n                .addClassName(languageDesc_clsName)\n```\n\n2. The another is style definition:\n``` swift\nlet languageLogo_clsName = CSSStyle([\n    .width(100),\n    .height(100),\n    .cornerRadius(10),\n    .paddingTLBT(10, 0, 15,0)\n])\n\nlet languageTitle_clsName = CSSStyle([\n    .font(.headline),\n    .foregroundColor(Color(red: 0x33/0xff, green: 0x33/0xff, blue: 0x33/0xff)),\n    .paddingEdges([.bottom], 10)\n])\n\nlet languageDesc_clsName = CSSStyle([\n    .font(.footnote),\n    .paddingHorizontal(10),\n    .foregroundColor(NormalDescColor),\n    .lineSpacing(2),\n    .flexHeight(min: 50, max: .infinity)\n])\n```\n## 2. use module system for reuse or create a custom design system.\n*module system* help to reuse some common style design across the whole app which can save you to write same codes everywhere or avoid to make some mistakes.\n\n### Without SwifUI-CSS:\nIf you change the style of Text(\"28 October 2014\"), you must change the style of Text(\"Objective-C,[7] Rust, Haskell, Ruby, Python, C#, CLU,[8] D[9]\") too.\n```swift\n// in html5.swift\n                HStack() {\n                    Text(\"Initial release:\")\n                        .font(Font.system(size: 14))\n                    \n                    Text(\"28 October 2014\")\n                    .font(Font.system(size: 12))\n                    .foregroundColor(NormalDescColor)\n\n                }\n// in swift.swift\n                HStack(alignment: .top) {\n                    Text(\"Influenced by:\")\n                        .font(Font.system(size: 14))\n                    \n                    Text(\"Objective-C,[7] Rust, Haskell, Ruby, Python, C#, CLU,[8] D[9]\")\n                    .font(Font.system(size: 12))\n                    .foregroundColor(NormalDescColor)\n\n                }\n```\n### With SwiftUI-CSS\nYou can change the definition of wikiDesc_clsName once for all.\n``` swift\nlet wikiDesc_clsName = CSSStyle([\n    .font(Font.system(size: 12)),\n    .foregroundColor(NormalDescColor)\n])\n\n// in html5.swift\n                HStack() {\n                    Text(\"Initial release:\")\n                        .font(Font.system(size: 14))\n                    \n                    Text(\"28 October 2014\")\n                    .addClassName(wikiDesc_clsName)\n\n                }\n// in swift.swift\n                HStack(alignment: .top) {\n                    Text(\"Influenced by:\")\n                        .font(Font.system(size: 14))\n                    \n                    Text(\"Objective-C,[7] Rust, Haskell, Ruby, Python, C#, CLU,[8] D[9]\")\n                    .addClassName(wikiDesc_clsName)\n\n                }\n```\n\n## the other benefits of using SwiftUI-CSS\n1. more easy to change a lot of styles when state change.\n``` swift\n// without swiftui-css\nif festival == 'Christmas' {\n     Text(\"Welcome everyone!\")\n     .font(.largeTitle)\n     .foreground(.white)\n     .background(.red)\n} else {\n        Text(\"Welcome everyone!\")\n     .font(.title)\n     .foreground(.darkGray)\n     .background(.white)\n}\n\n// with\nText(\"Welcome everyone!\")\n.addClassName(fesitval == 'Christmas' ? chrismas_clsName: normal_clsName)\n```\n2. Maybe a reachable way to convert html+css codes  to swiftui source\n3. write less code, clear to tell parameters meanings. For example. \n\u003e `.frame(minHeight: 50, maxheight: .infinity` to `.flexHeight(min: 50, max: .infinity)`\n\u003e `.padding(EdgeInset(top:10, leading: 15, bottom:0, trailing: 20)` to `.paddingTLBT(10,15,0,20)`\n4. You can combile some different style into one.\n```swift\nlet fontStyle = CSSStyle([.font(.caption)])\n        let colorStyle = CSSStyle([.backgroundColor(.red)])\n        \n        let finalStyle = fontStyle + colorStyle\n        print(\"finalStyle = \\(finalStyle)\")\n```\n5. use responsive class to make view larger on larger screen\n```swift\n// In iOS, if the sketch file designed for screen 375x667, the responsive fator should be compared to UIScreen.main.bounds.size.width.\nlet responsive = Responsive(UIScreen.main.bounds.size.width / 375)\nlet wikiDesc_clsName = CSSStyle([\n    .font(Font.system(size: responsive.r(12))),\n    .foregroundColor(NormalDescColor)\n    .paddingEdges([.bottom], responsive.r(10))\n])\n```\n\n\n","funding_links":[],"categories":["Swift","🌎 by the community"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhite%2FSwiftUI-CSS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhite%2FSwiftUI-CSS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhite%2FSwiftUI-CSS/lists"}