This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
private let reuseIdentifier = "Cell" | |
class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { | |
/* Return item size */ | |
var itemSize: CGSize { | |
let layout = self.collectionViewLayout as! UICollectionViewFlowLayout | |
return layout.itemSize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
private let reuseIdentifier = "Cell" | |
class CollectionViewController: UICollectionViewController { | |
/* Custom scrollView for paging */ | |
let pagingScrollView = UIScrollView() | |
/* Return item size */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class CustomSectionHeaderFlowLayout: UICollectionViewFlowLayout { | |
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { | |
var allAttributes = super.layoutAttributesForElements(in: rect)! | |
// re-add the header when disappearing | |
var headerIsVisible = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set new text with existing NSAttributedString | |
let titleAttributedString = NSMutableAttributedString(string: self.meetingTitles[indexPath.row], attributes: cell.meetingTitle.attributedText?.attributes(at: 0, effectiveRange: nil)) | |
// Set new attributedText | |
cell.meetingTitle.attributedText = titleAttributedString |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSAttributedString { | |
// MARK: - Makes a copy of the existing attributes for NSAttributedString and sets color for specific string(s) | |
func makeStringWithColor(forString stringArray: [String], withColor color: UIColor) -> NSMutableAttributedString { | |
// Existing attributes | |
let attributedString = NSMutableAttributedString(attributedString: self) | |
// Iterate through strings | |
for specifiedString in stringArray { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
func random() -> UIColor { | |
let colors = [ | |
UIColor(red:0.91, green:0.07, blue:0.14, alpha:1.0), | |
UIColor(red:0.94, green:0.23, blue:0.09, alpha:1.0), | |
UIColor(red:0.97, green:0.39, blue:0.05, alpha:1.0), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Date format | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "dd. MMMM" | |
// Output current date in format | |
dateFormatter.string(from: Date()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dynamically sizing cells | |
self.tableView.rowHeight = UITableViewAutomaticDimension | |
self.tableView.estimatedRowHeight = 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Listen for keyboard changes | |
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) | |
} | |
func keyboardWillShow(sender: NSNotification) { | |
if let keyboardSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns class type | |
type(of: Element) |
OlderNewer