Swiftpack.co - fatihbalsoy/SwiftyRuler as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fatihbalsoy.
fatihbalsoy/SwiftyRuler 1.0.0
Simple, Pixel-Accurate Ruler for iOS, macOS, and tvOS
⭐️ 0
🕓 1 week ago
iOS macOS tvOS
.package(url: "https://github.com/fatihbalsoy/SwiftyRuler.git", from: "1.0.0")

Alt text

Swift build License iOS macOS tvOS

SwiftyRuler is a very simple Swift package that implements an accurate ruler for any iOS device. Nothing more, nothing less.


To run the example project, clone the repo, and run pod install from the Example directory first.

Vertical Horizontal Document
Alt text Alt text Alt text


Swift Package Manager

To integrate using Apple's Swift Package Manager, add the following as a dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/fatihbalsoy/SwiftyRuler.git", from: "1.0.0")

Alternatively, navigate to your Xcode project, go to File > Add Packages... and search for https://github.com/fatihbalsoy/SwiftyRuler.


If you prefer not to use any of the aforementioned dependency managers, you can integrate SwiftyRuler into your project manually. Simply drag the files in the Sources folder into your Xcode project.


import SwiftyRuler
import UIKit

class ViewController : UIViewController, RulerDelegate {

    override func viewDidLoad() {

        let ruler = Ruler()
        ruler.delegate = self

        // Tick Lengths //
        ruler.longTickLength = 30
        ruler.shortTickLength = 10
        ruler.midTickLength = ruler.midLineLength(2)

        // Properties //
        ruler.pixelAccurate = true
        ruler.doubleUnits = true
        ruler.direction = .horizontal
        // ruler.doubleSided = false
        // Colors //
        ruler.backgroundColor = UIColor.label.withAlphaComponent(0.05)
        ruler.tickColor = .label
        ruler.labelColor = .label

        // Set Pixel Density //
        // ~ Useful for macOS and tvOS ~ //
        // Setup Constraints //

RulerDelegate functions

@objc optional func ruler(didPressAccuracyWarning ruler: Ruler, using event: UIEvent)

Triggered when accuracy disclaimer is pressed. Can be used to implement a user interface claiming the inaccuracy of the ruler and giving the option to enter a custom pixel density.

@objc optional func ruler(didPressCustomizePixelDensity ruler: Ruler, currentDensity: CGFloat, using event: UIEvent)

Triggered when the edit button is pressed. Can be used to implement a user interface to adjust the pixel density of the ruler.


  • GBDeviceInfo
    • Used to fetch PPI (Pixels per Inch) of iOS displays.


SwiftyRuler is available under the AGPL license. See the LICENSE file for more info.


Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

3 weeks ago

Initial release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics