Skip to content

Instantly share code, notes, and snippets.

View TheCodedSelf's full-sized avatar

Keegan Rush TheCodedSelf

View GitHub Profile
@TheCodedSelf
TheCodedSelf / Disable Alert Button.swift
Last active March 31, 2024 18:00
Disable Alert Controller button if Alert Controller text field is empty or whitespace
import UIKit
// Create an alert controller
let alertController = UIAlertController(title: "Alert", message: "Please enter text", preferredStyle: .alert)
// Create an OK Button
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
// Print "OK Tapped" to the screen when the user taps OK
print("OK Tapped")
}
@TheCodedSelf
TheCodedSelf / xopen
Last active September 8, 2016 05:19
Bash script that opens any xcworkspace or xcodeproj found in the current directory in Xcode
#!/bin/bash
#
# Opens any xcworkspace or xcodeproj found in the current directory in Xcode.
#
openfile () (
file="$1"
echo "Opening $file";
open $file;
)
import UIKit
extension UIView
{
func shake()
{
let shakeAngle = (5 * M_PI) / 360
let shakeRotation = CAKeyframeAnimation(keyPath: "transform.rotation")
@TheCodedSelf
TheCodedSelf / Misc.swift
Last active January 23, 2016 10:22
Miscellaneous
// Random number between 0 and n
let n = 42
let randomNumber = Int(arc4random_uniform(n))
// Instantiate a view controller that exists in a storyboard
let storyboardName = "Main"
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let storyboardIdForViewController = "MyVC" // Specified in IB on the specific view controller instance
let myVc: MyViewController = storyboard.instantiateViewControllerWithIdentifier(storyboardIdForViewController) as! MyViewController
@TheCodedSelf
TheCodedSelf / NavigationBars.swift
Last active January 19, 2016 17:52
Playing with UINavigationBars
// Set title text
self.navigationItem.title = "Title"
// Set title text color
let desiredColor = UIColor.whiteColor()
navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : desiredColor]
// Set back bar button item title
let backButton = UIBarButtonItem(title: "Back", style: .Plain, target: nil, action: nil)
self.navigationItem.backBarButtonItem = backButton
@TheCodedSelf
TheCodedSelf / VisibleHeight.m
Created January 17, 2016 10:38
iOS: Get the visible height of a table view (minus the tab bar and navigation bar
CGFloat height = self.tableView.bounds.size.height - [UIApplication sharedApplication].statusBarFrame.size.height;
height = height - self.navigationController.navigationBar.frame.size.height;
height = height - self.tabBarController.tabBar.bounds.size.height;