Skip to content

Instantly share code, notes, and snippets.

@MylesCaley
MylesCaley / MultipleOfSameConstraints.swift
Created November 18, 2016 17:31
its possible to create multiple constraints for the same object, then change the priority
// instead of creating and destroying constraints all the time we can just
// add multiple constraints on the same object and then change the priority
// and indicate which one is active
if feedItem!.prototypeUpdate?.media.count <= 1 {
mediaViewWidthConstraintLarge.priority = 995
mediaViewWidthContraint.priority = 999
mediaViewWidthConstraintLarge.isActive = true
mediaViewWidthContraint.isActive = false
} else {
mediaViewWidthConstraintLarge.priority = 999
@MylesCaley
MylesCaley / ExpandUITextView.swift
Last active January 24, 2017 19:57
When text is too small to fit in UITextView
extension UITextView {
func sizeThatWillFitAllText()->CGFloat {
return self.sizeThatFits((self.frame.size)).height
}
}
self.textViewHeightConstraintOutlet.constant = desiredTextViewHeight < CGFloat(75) ? desiredTextViewHeight : CGFloat(75)
let textViewWantsHeightObservable = self.textViewHeightConstraintOutlet
@MylesCaley
MylesCaley / LandscapeOnFullScreen.swift
Last active February 1, 2019 03:56
When you have a portrait-only app you may still want to allow rotation when the app plays full screen media. This is a decent solution by creating a notification to signal a "full screen". Only tested on iOS9.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var isFullScreen = false
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// create notifications from wherever to signal fullscreen