Toolbar
  • March 11, 2024

Slow Animations Debug mode

If you want a Toolbar that works with the keyboard, please see here. https://github.com/1amageek/OnTheKeyboard

Installation


CocoaPods

  • Inset pod 'Toolbar' to your Podfile.
  • Run pod install

Usage


Height and Width of the Toolbar are determined automatically. Do not set frame.

Initialization.

let toolbar: Toolbar = Toolbar()

let toolbar: Toolbar = Toolbar()

lazy var camera: ToolbarItem = {
let item: ToolbarItem = ToolbarItem(image: #imageLiteral(resourceName: “camera”), target: nil, action: nil)
return item
}()

lazy var microphone: ToolbarItem = {
let item: ToolbarItem = ToolbarItem(image: #imageLiteral(resourceName: “microphone”), target: nil, action: nil)
return item
}()

lazy var picture: ToolbarItem = {
let item: ToolbarItem = ToolbarItem(image: #imageLiteral(resourceName: “picture”), target: nil, action: nil)
return item
}()

var toolbarBottomConstraint: NSLayoutConstraint?

override func loadView() {
super.loadView()
self.view.addSubview(toolbar)
self.toolbarBottomConstraint = self.toolbar.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0)
self.toolbarBottomConstraint?.isActive = true
}

override func viewDidLoad() {
super.viewDidLoad()
self.toolbar.maximumHeight = 100
self.toolbar.setItems([self.camera, self.picture, self.microphone], animated: false)
}

Hide items

func hideItems() {
self.camera.setHidden(false, animated: true)
self.microphone.setHidden(false, animated: true)
self.picture.setHidden(false, animated: true)
}

Stretchable TextView

You can control the height by setting maximumHeight.

// ViewController

override func viewDidLoad() {
super.viewDidLoad()
self.toolbar.maximumHeight = 100
let textView: UITextView = UITextView(frame: .zero)
textView.delegate = self
textView.font = UIFont.systemFont(ofSize: 14)
self.toolbar.setItems([textView], animated: false)
}

// UITextViewDelegate
func textViewDidChange(_ textView: UITextView) {
let size: CGSize = textView.sizeThatFits(textView.bounds.size)
if let constraint: NSLayoutConstraint = self.constraint {
textView.removeConstraint(constraint)
}
self.constraint = textView.heightAnchor.constraint(equalToConstant: size.height)
self.constraint?.priority = UILayoutPriorityDefaultHigh
self.constraint?.isActive = true
}

var constraint: NSLayoutConstraint?

GitHub


View Github

#autolayout #inputbar #ios #swift #toolbar
YOU MIGHT ALSO LIKE...
CameraBackground

Features Both front and back camera supported. Flash modes: auto, on, off. Countdown timer. Tap to focus. Pinch to zoom. Usage  

DKCamera

Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so ...

HorizonSDK-iOS

Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...

LLSimpleCamera

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video ...

RSBarcodes_Swift

RSBarcodes allows you to read 1D and 2D barcodes using the metadata scanning capabilities introduced with iOS 7 and generate ...