Latest 1.9.0
Homepage https://github.com/UseSweet/SweetUIKit
License MIT
Platforms ios 9.0, watchos 2.0, tvos 9.0, requires ARC
Frameworks UIKit
Authors

Version
License
Platform

Dequeuing Cells

UITableView

// Before
let cell = tableView.dequeueReusableCell(withIdentifier: "TitleCell", for: indexPath) as! TitleCell

// After
let cell = tableView.dequeue(TitleCell.self, for: indexPath)

UICollectionView

// Before
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell

// After
let cell = collectionView.dequeue(CollectionViewCell.self, for: indexPath)

Registering Cells

Simple protocol extensions to simplify registering a cell in UITableViewController and UICollectionViewController.

Before:

self.tableView.registerClass(ItemCell.self, forCellReuseIdentifier: "ItemCell")

After:

self.tableView.register(ItemCell.self)

Also, accessing the cell identifier is as easy as using ItemCell.reuseIdentifier.

UIAlertController

Dismissable alert

let alertController = UIAlertController.dismissableAlert(title: "Not allowed access", message: "Please contact your admin to get access.")
self.presentViewController(alertController, animated: true, completion: nil)

Destructive confirmation alert

let alertController = UIAlertController.destructiveConfirmationAlert(message: "Are you sure you want to log out?", destructiveActionTitle: "Log out") {
    self.controllerDelegate?.settingsControllerDidPressLogoutButton(self)
}
self.presentViewController(alertController, animated: true, completion: nil)

Error alert

let alertController = UIAlertController.errorAlert(error)
self.presentViewController(alertController, animated: true, completion: nil)

Progress alert

let progressAlert = UIAlertController.progressAlert("Creating album...")
self.presentViewController(progressAlert, animated: true, completion: nil)
self.fetcher.createAlbum(title: self.titleTextField.text, photos: self.selectedPhotos) { error in
    progressAlert.dismissViewControllerAnimated(true) {
        if let error = error {
            let alertController = UIAlertController.errorAlert(error)
            self.presentViewController(alertController, animated: true, completion: nil)
        } else {
            // Success
        }
    }
}

UILabel

Calculate width

let width = self.usernameLabel.width()
// Do something with new width

UIView

Autolayout

Fill superview

Set a view’s top, left, right and bottom anchors to be the same as the superviews. Accepts an optional UIEdgeInsets argument. Values can be all positive for margins, as it handles the negative values for bottom and right constants already.

    view.fillSuperview()

    anotherView.fillSuperview(UIEdgeInsets(top: 10, left: 10, bottom: 80, right: 10))

Set hight and width anchors directly

    view.set(height: 30.0)
    view.set(width: 50.0)

Attach to top

Great for toolbars, attaches to view to the top of the superview. Doesn’t set a height. If you pass a view controller, it will attach to viewController.topLayoutGuide.bottomAnchor instead of superview.topAnchor.

    toolbar.attachToTop(viewController: self)

Shake

self.fetcher.authenticate(username, password: password) { clientID, clientSecret, accessToken, refreshToken, expiresIn, error in
    if let error = error {
        // Update UI to display error
        self.tableView.shake()
    } else {
      // success
    }
}

UIImage

Centered frame

let image = UIImage(named: "art.png")!
let frame = image.centeredFrame()
// Do something with new frame

Image with colour

let image = UIImage(color: .red)
button.setBackgroundImage(image, for: .normal)

or, if you need the image to have specific dimensions

let image = UIImage(color: .red, size: someSize)

Colours from RGBA values

Create images using rgba(255,255,255,1.0) values.

    UIColor(r: 200, b: 120, c: 255)
    UIColor(r: 200, b: 120, c: 25, 0.5)

UIViewController

Application window

let window = self.applicationWindow()

Installation

SweetUIKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SweetUIKit'

SweetUIKit is also available through Carthage. To install
it, simply add the following line to your Cartfile:

github "UseSweet/SweetUIKit" ~> 1.0

License

SweetUIKit is available under the MIT license. See the LICENSE file for more info.

Author

Bakken & Bæck, @use_sweet

Latest podspec

{
    "name": "SweetUIKit",
    "summary": "Helpers and sugar for the UIKit framework.",
    "version": "1.9.0",
    "homepage": "https://github.com/UseSweet/SweetUIKit",
    "license": "MIT",
    "authors": {
        "Use Sweet": "[email protected]"
    },
    "source": {
        "git": "https://github.com/UseSweet/SweetUIKit.git",
        "tag": "1.9.0"
    },
    "social_media_url": "https://twitter.com/use_sweet",
    "platforms": {
        "ios": "9.0",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*.swift",
    "frameworks": "UIKit",
    "resources": "Resources/**/*",
    "resource_bundles": {
        "SweetUIKitResources": [
            "Resources/**/*"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This