{"id":19110073,"url":"https://github.com/hkellaway/autolycus","last_synced_at":"2025-10-06T18:33:31.331Z","repository":{"id":77939312,"uuid":"109451359","full_name":"hkellaway/Autolycus","owner":"hkellaway","description":"Autolayout DSL :triangular_ruler:","archived":false,"fork":false,"pushed_at":"2020-05-16T05:57:38.000Z","size":106,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-04-30T20:47:08.654Z","etag":null,"topics":["autolayout","autolayout-constraints","ios","swift"],"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/hkellaway.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-11-03T23:24:12.000Z","updated_at":"2020-05-16T05:57:38.000Z","dependencies_parsed_at":"2023-03-05T08:45:37.933Z","dependency_job_id":null,"html_url":"https://github.com/hkellaway/Autolycus","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/hkellaway/Autolycus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkellaway%2FAutolycus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkellaway%2FAutolycus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkellaway%2FAutolycus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkellaway%2FAutolycus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hkellaway","download_url":"https://codeload.github.com/hkellaway/Autolycus/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hkellaway%2FAutolycus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265508323,"owners_count":23779119,"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":["autolayout","autolayout-constraints","ios","swift"],"created_at":"2024-11-09T04:23:31.751Z","updated_at":"2025-10-06T18:33:26.296Z","avatar_url":"https://github.com/hkellaway.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autolycus :triangular_ruler:\n\n![Swift version](https://img.shields.io/badge/Swift-5.0-orange.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/badge/License-MIT-lightgray.svg)](https://raw.githubusercontent.com/hkellaway/Autolycus/master/LICENSE)\n[![Build Status](https://travis-ci.org/hkellaway/Autolycus.svg?branch=develop)](https://travis-ci.org/hkellaway/Autolycus)\n\nAutolayout DSL for writing layout and constraints programmatically.\n\n## Getting Started\n\n- [Download Autolycus](https://github.com/hkellaway/Autolycus/archive/master.zip) and do a `pod install` on the included `AutolycusDemo` app to see Autolycus in action\n\n### Installation with CocoaPods\n\n```ruby\npod 'Autolycus', :git =\u003e 'git@github.com:hkellaway/Autolycus.git', :tag =\u003e '0.2.0'\n```\n\n### Installation with Carthage\n\n```\ngithub \"hkellaway/Autolycus\"\n```\n\n## Usage\n\nAutolycus is simply syntactic sugar around the verbose programmatic layout API.\n\n### Example\n\nLet's look at a simple example of aligning two views next to each other.\n\nWith Autolycus :triangular_ruler::\n\n```\nfirstView.constrain().size(of: secondView)\nfirstView.constrain().top(to: secondView)\nfirstView.constrain().leadingToTrailing(of: secondView)\n```\n\nA bit more verbose with `NSLayoutDimension` (iOS 9.0+):\n\n```\nfirstView.translatesAutoresizingMaskIntoConstraints = false\nfirstView.widthAnchor.constraint(equalTo: secondView.heightAnchor).isActive = true\nfirstView.heightAnchor.constraint(equalTo: secondView.heightAnchor).isActive = true\nfirstView.topAnchor.constraint(equalTo: secondView.topAnchor).isActive = true\nfirstView.leadingAnchor.constraint(equalTo: secondView.trailingAnchor).isActive = true\n```\n\nClunkiest of all, with `NSLayoutConstraint`:\n\n```\nfirstView.translatesAutoresizingMaskIntoConstraints = false\nlet width = NSLayoutConstraint(item: firstView, attribute: .width, relatedBy: .equal, toItem: secondView, attribute: .width, multiplier: 1, constant: 0)\nlet height = NSLayoutConstraint(item: firstView, attribute: .height, relatedBy: .equal, toItem: secondView, attribute: .height, multiplier: 1, constant: 0)\nlet leadingToTrailing = NSLayoutConstraint(item: firstView, attribute: .leading, relatedBy: .equal, toItem: secondView, attribute: .trailing, multiplier: 1, constant: 0)\nNSLayoutConstraint.activate([width, height, top, leadingToTrailing])\n```\n\nThe purpose of Autolycus is to simplify constraint creation and obfuscate odd API details.\n\nAutolycus follows the usage passing of calling `constrain()` on the view adopting programmatic layout then chaining together a list of desired constraints, which are automatically applied.\n\n### Convenience functions\n\nHere is a list of convneience functions that Autolycus provides. Each of these produces one or more constraints that are applied to views called upon.\n\nNote that these functions can be called with various parameters to specify placement, such as offeset or insets. \n\nConstraints are activated by default, but can be made inactive by providing the `isActive` parameter as `false`.\n\n**For single view**\n\n* `width` (e.g. `view.constrain().width(10)`)\n* `height`\n* `size`\n\n**For relationship between two views**\n\n* `width(to view:)` (e.g. `view.constrain().width(to view: otherView)`)\n* `height(to view:)`\n* `centerX(to view:)`\n* `centerY(to view:)`\n* `leading(to view:)`\n* `left(to view:)`\n* `trailing(to view:)`\n* `right(to view:)`\n* `top(to view:)`\n* `bottom(to view:)`\n* `inCenter(of view:)`\n* `edges(to view:)`\n* `size(of view:)`\n* `origin(to view:)`\n* `leadingToTrailing(of view:)`\n* `leftToRight(of view:)`\n* `trailingToLeading(of view:)`\n* `rightToLeft(of view:)`\n* `topToBottom(of view:)`\n* `bottomToTop(of view:)`\n\n**For relationship to superview**\n\n* `widthToSuperview` (e.g. `view.constrain().widthToSuperView()`)\n* `heightToSuperview`\n* `centerXToSuperview`\n* `centerYToSuperview`\n* `leadingToSuperview`\n* `leftToSuperview`\n*`trailingToSuperview`\n* `rightToSuperview`\n* `topToSuperview`\n* `bottomToSuperview`\n* `centerInSuperview`\n* `edgesToSuperview`\n* `sizeOfSuperview`\n* `originToSuperview`\n\n### Discussion\n\nThere is nothing fancy going on here. Autolycus simply creates `NSLayoutConstraint` instances in a more literate way with reasonable defaults. It also obfuscates the oft-forgotten necessity of setting `translatesAutoresizingMaskIntoConstraints = false` and `isActive = true`.\n\nTo that point, our original example could be written more manually with Autolycus just used to generate constraints:\n\n```\nfirstView.translatesAutoresizingMaskIntoConstraints = false\n        \nlet constraintsArray: [NSLayoutConstraint] = firstView.size(of: secondView, isActive: false)\n    + [firstView.top(to: secondView, isActive: false)]\n    + [firstView.leadingToTrailing(of: secondView, isActive: false)]\n        \nNSLayoutConstraint.activate(constraintsArray)\n```\n\nBecause Autolycus only creates `NSLayoutConstraint` instances, these can be stored for later usage to take advantage of animation or hiding/moving views by way of constraint manipulation.\n\n## Credits\n\nAutolycus was created by [Harlan Kellaway](http://harlankellaway.com).\n\n## License\n\nAutolycus is available under the MIT license. See the [LICENSE](https://raw.githubusercontent.com/hkellaway/Autolycus/master/LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkellaway%2Fautolycus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhkellaway%2Fautolycus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhkellaway%2Fautolycus/lists"}