Convenient domain specific language for writing programmatic UI built over UIKit and more.

Overview

XYKit

Swifty and convenient domain specific language for creating programmatic UI in a more declarative way and more than that. Built on top of UIKit using extensions-only minimalistic approach.

Installation using Swift Package Manager:

    1. Open your project in Xcode or make a new one
    1. Select it it at the top of the Project Navigator (left panel with file structure of your project)
    1. Switch to Package Dependencies tab
    1. Tap plus to add a new dependancy
    1. In the top rightmost corner of the window paste this link https://github.com/goldena/XYKit into the search field
    1. You can tap twice on the newly added dependency to choose its update rules. The best approach in terms of maintainability is to select Version rules, for example from 2.0.0 till 3.0.0 to make sure a new major version of the dependency will not have any API breaking changes.

Features:

  • No need to manually activate newly created constraints: '.isActive = true'

  • No need to 'translatesAutoresizingMaskIntoConstraints = false', no need to 'addArrangedSubview()' if you are adding subviews using:

someView.superview(is: view) // Which I consider more natural than 'view.addSubview(someView)'

view.subview(is: aView)
view.subviews(are: anotherView, yetAnotherView)

Example 1:

// UIKit:
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false

imageView.heightAnchor.constraint(equalToConstant: 32).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 64).isActive = true

// XYKit:
view.subviews(are: label, imageView)

imageView.width(32)
imageView.height(64)

// Or even shorter:
imageView.size(width: 32, height: 64)

// What if constraints were inequalities like these:
imageView.widthAnchor.constraint(lessThanOrEqualToConstant: 32).isActive = true
imageView.heightAnchor.constraint(lessThanOrEqualToConstant: 64).isActive = true

// XYKit:
imageView.size(width: 32, height: 64, or: .less)

Example 2:

imageView.leading(snapTo: .margin)                          // Constraint leading anchor of the imageView to the leading margin of the superview
imageView.centerY()                                         // Center view in superview

label.leading(snapTo: gameImageView.trailing).offset(16)    // Constraint leading anchor of the label's trailing anchor, plus constant
  • As you might have noticed method chaining is available. Keep in mind though that every func in XYKit returns either a view or a constraint(s) as @discardableResult, thus in order to use chaining you have to consider a moment when a view becomes a constraint(s). That is quite easy - it happens when you 'snapTo' or 'center', or change 'size'. In case of doubts feel free to check func type signature.

Example 3:

tableView.sidesX(snapTo: .padding(20))          // Constraint horizontal sides to leading and trailing anchors of superview with the padding of 20
tableView.centerX()                             // Center tableView in superview

tableView.top(snapTo: .safeArea)                // Constraint top anchor of tableView to screen's safe area.
tableView.bottom(snapTo: self)                  // Constraint bottom anchor of tableView to superview's bottom anchor

Example 4:

mainStackView
            .superview(is: self)
            .subviews(are: titleStackView, timeStackView)
            .insets(left: 8, top: 8, right: 16, bottom: 16) // insets for UIStackView
            .spacing(20)                                    // spacing between arranged subviews inside UIStackView
            .sides(snapTo: .safeArea)                       // Snap all sides to the screen's safe areas
        
let tap = UITapGestureRecognizer(target: self, action: #selector(imageViewTapped))
imageView.tappable(with: tap)                               // Another extension for UIView                

##Disclaimer: this is my initial take on the XYKit, there is a lot of space for refactoring, improvements and no doubt - some bugs to be found and squashed. Contributions, suggestions, pull requests are welcomed and encouraged.

You might also like...
A set of frameworks making iOS development more fun

A set of frameworks making iOS development more fun, developed by N8ive Apps Frameworks InterfaceKit AuthKit CoreKit (in progress) NetworkKit (in prog

React.js like Mixin. More powerful Protocol-Oriented Programming.

Mixin ๐Ÿน Why? Swift is Protocol-Oriented Programming, and it's more powerful by default implementations of extensions of protocols. You can mixin meth

Application to test MVVM architecture with Combine and UIKit librarys.

Application to test MVVM architecture with Combine and UIKit librarys.

A simple and elegant UIKit for iOS.
A simple and elegant UIKit for iOS.

HamsterUIKit A simple and elegant UIKit(Chart) for iOS, written in Swift. ๐Ÿ“Š Curve and bar Charts. ๐Ÿ’ก Protocols are designed based on UIKit(UITableVie

Neumorphism framework for UIKit.
Neumorphism framework for UIKit.

NeumorphismKit is neumorphism framework for UIKit. Requirements iOS 12.0+ Swift 5.1+ Versions NeumorphismKit version Xcode version 1.0.0 Xcode 11+ 1.1

Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements
Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements

SwiftUIKitView Easily use UIKit views in SwiftUI. Convert UIView to SwiftUI View Create Xcode Previews from UIView elements SwiftUI functional updatin

Make ComposableArchitecture work with UIKit

ComposableUIKit The ComposableArchitecture (TCA) library provides a way of structuring Swift code with the Redux-pattern. It is highly optimized for S

Combine publisher bridges for UIKit
Combine publisher bridges for UIKit

Combine publisher bridges for UIKit

Swift extensions for UIKit.framework.

XUIKit Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation XUIKit is a

Owner
Denis Goloborodko
Generalist, minimalist. Father, husband. iOS Developer. Manager. MBA.
Denis Goloborodko
A Simple Camera App With Programmatic UI

CameraApp-ProgrammaticUI Hey there! This is a simple Camera Application that I and Sahab Alharbi worked on as part of Tuwaiq's iOS bootcamp projects.

null 0 Dec 4, 2021
๐ŸŽธ๐ŸŽธ๐ŸŽธ Common categories for daily development. Such as UIKit, Foundation, QuartzCore, Accelerate, OpenCV and more.

?????? Common categories for daily development. Such as UIKit, Foundation, QuartzCore, Accelerate, OpenCV and more.

77ใ€‚ 423 Jan 4, 2023
Blobmorphism is a brand new design language I've created to break free of the material overload in iOS, built in SwiftUI. Everything feels smooth and fluid.

Blobmorphism is a brand new design language I've created to break free of the material overload in iOS, built in SwiftUI. Everything feels smooth and fluid.

Ethan Lipnik 89 Nov 29, 2022
A set of UIKit helpers that simplify the usage of UIKit view's and controller's in SwiftUI.

A set of UIKit helpers that simplify the usage of UIKit view's and controller's in SwiftUI. Many of these helpers are useful even in a pure UIKit project.

SwiftUI+ 6 Oct 28, 2022
A Swift material design UI module which paints over the parent view when the switch is on.

:octocat: ?? RAMPaperSwitch is a Swift material design UI module which paints over the parent view when the switch is turned on. iOS library by @Ramotion

Ramotion 2.9k Dec 29, 2022
Stencil is a simple and powerful template language for Swift.

Stencil Stencil is a simple and powerful template language for Swift. It provides a syntax similar to Django and Mustache. If you're familiar with the

Stencil Project 2.2k Jan 4, 2023
macOS GUI Library for the Nim Programming Language

NimCocoa NimCocoa is an experimental implementation of a Native GUI for the Nim programming language running on macOS. Rather than rely on low level c

null 32 Dec 8, 2022
Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment.

Hackaton-ATM-PJ04 Swift programming language hackathon. Implementation of the main logic of working with an ATM in the Playground environment. The tas

Raman Kozar 2 Oct 4, 2022
High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

Haoking 336 Nov 26, 2022
Custom emojis are a fun way to bring more life and customizability to your apps.

Custom emojis are a fun way to bring more life and customizability to your apps. They're available in some of the most popular apps, such as Slack, Di

Stream 244 Dec 11, 2022