Skip to content

Instantly share code, notes, and snippets.

View tsraveling's full-sized avatar

Tim Raveling tsraveling

View GitHub Profile
@tsraveling
tsraveling / flexible-tableview.swift
Last active December 24, 2018 22:32
Flexible tableview setup
// Set up tableview
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 45
@tsraveling
tsraveling / webview-delegate.swift
Created April 18, 2017 23:53
UIWebView delegate
// MARK: - UIWebView delegate -
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
return true
}
func webViewDidStartLoad(_ webView: UIWebView) {
}
@tsraveling
tsraveling / textview-delegate.swift
Created April 18, 2017 23:53
UITextView delegate
// MARK: - UITextViewDelegate -
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
textView.resignFirstResponder()
return false
}
return true
}
@tsraveling
tsraveling / textfield-delegate.swift
Last active August 23, 2017 19:21
UITextField delegate
// MARK: - UITextFieldDelegate -
func textFieldDidBeginEditing(_ textField: UITextField) {
let screen_offset = (UIScreen.main.bounds.size.height - 330) - 60 // Gets offset based on screen size and keyboard / nav height
let y = textField.frame.origin.y - screen_offset
self.scrollView.setContentOffset(CGPoint(x: 0, y: y > 0 ? y : 0), animated: true)
}
func textFieldDidEndEditing(_ textField: UITextField) {
@tsraveling
tsraveling / collectionview-delegate-datasource.swift
Created April 18, 2017 23:54
UICollectionView delegate and datasource
// MARK: - UICollectionView Datasource and Delegate -
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// TODO: Implement count.
@tsraveling
tsraveling / tableview-delegate-datasource.swift
Last active June 13, 2019 19:41
UITableView delegate and datasource
// MARK: - TableView delegate and datasource
extension SomeClass: UITableViewDataSource, UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
@tsraveling
tsraveling / searchbar-delegate.swift
Created April 18, 2017 23:56
UISearchBar delegate
// MARK: - UISearchBarDelegate -
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
self.filteredUsers = nil
self.tableView.reloadData()
searchBar.resignFirstResponder()
@tsraveling
tsraveling / print-fonts.swift
Created April 18, 2017 23:56
Print font names
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName )
print("Font Names = [\(names)]")
}
@tsraveling
tsraveling / prepare-for-segue.swift
Created April 18, 2017 23:56
Prepare for segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
@tsraveling
tsraveling / menu-tableview-delegate.swift
Created April 18, 2017 23:57
Menu UITableView delegate
// MARK: - Menu UITableView Delegate and Datasource -
enum MenuItem : String {
case <#T##key#> = "<#T##Value#>"
static var items = [ <#T##all values#>]
}
func numberOfSections(in tableView: UITableView) -> Int {