UIHelper

1.1.0

This library is a collection of helper classes and extensions to make UIKit/SwiftUI development easier
NikSativa/UIHelper

What's New

1.1.0

2024-06-18T08:48:13Z

Full Changelog: 1.0.3...1.1.0

UIHelper

This library is a collection of helper classes and extensions to make UIKit development easier.

AutoLayoutBuilder

AutoLayoutBuilder is a class that allows you to create/activate constraints using a simple and readable syntax.

let constraintsResult = AutoLayoutBuilder.activate {
    subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    subview.heightAnchor.constraint(equalTo: view.heightAnchor)

    if isOptional {
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    }

    if isOptional {
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    } else {
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    }

    if isOptional {
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    } else {
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
        subview.widthAnchor.constraint(equalTo: view.widthAnchor)
    }

    isOptional ? subview.widthAnchor.constraint(equalTo: view.widthAnchor) : nil
    isOptional ? nil : subview.widthAnchor.constraint(equalTo: view.widthAnchor)

    if #available(iOS 13, *) {
        subview.heightAnchor.constraint(equalTo: view.heightAnchor)
    }

    for _ in 0..<2 {
        subview.heightAnchor.constraint(equalTo: view.heightAnchor)
    }

    [subview.heightAnchor.constraint(equalTo: view.heightAnchor)]
}

ModalPresenter

ModalPresenter is a class that allows you to present a view controller as a modal view controller.

let subject: ModalPresenter = .init(appRootViewControllerProvider: ...)
subject.lineUp(modalViewController)

KeyboardHandler

Keyboard Handler is a class that allows you to handle keyboard events and scroll content to a visible position.

private let keyboardHandler: KeyboardHandler = .init()

override func viewDidLoad() {
    super.viewDidLoad()
    keyboardHandler.enable(for: .init(view: scrollView, touchView: view, keyboardPadding: 16),
                           excluded: { [weak self] in
                               return [self?.emailTextField, self?.passwordTextField].filterNils()
                           })
}

TransparentTouchView

TransparentTouchView allows you to create a view that is transparent to touch events. The best example is when keyaboard is shown and user want tap some button on the screen. Then this view will handle touch on screen, but not locking touch on button. As result keyboard is hidding and button is pressed.

private let touchView = TransparentTouchView()

override func viewDidLoad() {
    super.viewDidLoad()
    view.addAndFill(touchView)
    touchView.action = { [weak self] in
        self?.view.endEditing(true)
    }
}

LabelLinksHandler

LabelLinksHandler allows you to detect tap on links in a UILabel.

@IBOutlet private weak var label: UILabel!
private let linkHandler: LabelLinksHandler<URL> = .init()
override func viewDidLoad() {
    super.viewDidLoad()
    linkHandler.label = label
    linkHandler.action = { [weak self] url in
        print(url)
    }
}

func configure(with viewModel: ViewModel) {
    label.text = viewModel.text
    linkHandler.links = viewModel.urls
}

ViewStyle

ViewStyle is a class that allows you to easily style the UI components that you need.

let style = [
    .backgroundColor(.blue),
    .border(.magenta, 10),
    .shadow(radius: 20, opacity: 0.9, offset: .init(width: 11, height: 11), color: .black),
    .cornerRadius(12),
    .clipsToBounds(false),
    .tintColor(.white)
]

style.apply(to: viewOne)
style.apply(to: viewTwo)
style.apply(to: viewThree)

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Thu Oct 17 2024 17:08:47 GMT-0900 (Hawaii-Aleutian Daylight Time)