This file contains hidden or 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
| addedView = UIView() | |
| addSubview(addedView) | |
| addedView.translatesAutoresizingMaskIntoConstraints = false | |
| addConstraints([ | |
| NSLayoutConstraint(item: addedView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0), | |
| NSLayoutConstraint(item: addedView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0), | |
| NSLayoutConstraint(item: addedView, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 1.0, constant: 0), | |
| NSLayoutConstraint(item: addedView, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 1.0, constant: 0) |
This file contains hidden or 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
| let attributedText = NSMutableAttributedString( | |
| string: "First string", | |
| attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .semibold)]) | |
| attributedText.append(NSAttributedString( | |
| string: "Bold string", | |
| attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14, weight: .heavy)])) | |
| attributedText.append(NSAttributedString( | |
| string: "Last string.", |
This file contains hidden or 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
| let appVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String |
This file contains hidden or 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 ModularView: UIView { | |
| // MARK: - Meta properties | |
| let xibName = "ModularView" | |
This file contains hidden or 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 | |
| public extension UIDevice { | |
| static let modelName: String = { | |
| var systemInfo = utsname() | |
| uname(&systemInfo) | |
| let machineMirror = Mirror(reflecting: systemInfo.machine) | |
| let identifier = machineMirror.children.reduce("") { identifier, element in | |
| guard let value = element.value as? Int8, value != 0 else { return identifier } |
This file contains hidden or 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
| @objc func keyboardWillShow(_ notification: NSNotification) { | |
| let keyboardAnimationDetail = notification.userInfo | |
| let animationCurve: Int = { | |
| if let keyboardAnimationCurve = keyboardAnimationDetail?[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int { | |
| let curve: Int? = UIView.AnimationCurve(rawValue: keyboardAnimationCurve)?.rawValue | |
| return curve ?? 0 | |
| } else { | |
| return 0 | |
| } |
This file contains hidden or 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 MyViewController: UIScrollViewDelegate { | |
| func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
| if scrollView == tableView { // Table view for example | |
| var scrollY = scrollView.contentOffset.y + scrollView.contentInset.top + 40 | |
| if scrollY < 0 { scrollY = 0 } | |
| constraintToChange.constant = -scrollY | |
| if 0...10 ~= scrollY { viewToHide.alpha = 1 - (scrollY.rounded() / 10.0) } | |
This file contains hidden or 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
| // | |
| // Storage.swift | |
| // | |
| import Foundation | |
| class Storage { | |
| // MARK: - Keys | |
This file contains hidden or 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 UIView { | |
| func setConstraint(_ constraintBlock: ((UIView) -> Void)) { | |
| translatesAutoresizingMaskIntoConstraints = false | |
| constraintBlock(self) | |
| layoutIfNeeded() | |
| } | |
This file contains hidden or 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 Foundation | |
| import UIKit | |
| class ModalScreenVC: UIViewController { | |
| // MARK: - Outlets | |
| /// A subview filling this controller's view with desired top margin | |
| @IBOutlet private var contentView: UIView! | |
OlderNewer