Skip to content

Instantly share code, notes, and snippets.

View mushu8's full-sized avatar

Alexandre Sagette mushu8

View GitHub Profile
import UIKit
class ASLabel: UILabel {
fileprivate var edgeInsets: UIEdgeInsets = UIEdgeInsets(top: 0,
left: 0,
bottom: 0,
right: 0)
@IBInspectable
@mushu8
mushu8 / gist:7cd8cf7be948f09b0b25af1e3371333c
Created May 15, 2018 16:07
animate an imageView from a cell to a navbar
func animateSelection(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {
let burgerCell = collectionView.cellForItem(at: indexPath) as! BurgerCollectionViewCell
let burgerImageView = burgerCell.thumbnailImageView!
let snapshotImageViewFrame = self.view.convert(burgerImageView.frame,
from: burgerImageView.superview)
let snapshotImageView = burgerImageView.snapshotView(afterScreenUpdates: true)!
self.snapshotView = snapshotImageView
extension UILabel{
func getRealWidth() -> CGFloat?{
guard let font = font else{
return nil
}
return (text! as NSString).sizeWithAttributes([NSFontAttributeName:font]).width
}
}
extension UIScreen {
enum SizeType: CGFloat {
case Unknown = 0.0
case iPhone4 = 960.0
case iPhone5 = 1136.0
case iPhone6 = 1334.0
case iPhone6Plus = 1920.0
}
@mushu8
mushu8 / isNilOrEmpty.swift
Last active August 29, 2015 14:27 — forked from kristopherjohnson/isNilOrEmpty.swift
Swift: determine whether optional String, NSString, or collection is nil or empty
import Foundation
/**
Determine whether Optional collection is nil or an empty collection
:param: collection Optional collection
:returns: true if collection is nil or if it is an empty collection, false otherwise
*/
public func isNilOrEmpty<C: CollectionType>(collection: C?) -> C? {
switch collection {
@mushu8
mushu8 / gist:62556029e7e8f9c1e104
Created April 2, 2015 13:23
call ws to update local json settings
# 1. get the xcode plist file path
# 2. read server url from plist file
# 3. read json settings file name from plist file
# 4. create temporary file for curl body response
# 5. curl api/settings web service and get http code
# 6. if http code is 200, feed the settigns file with new json
# 7. clean temp file
# 1. info plist path
infoplist="${INFOPLIST_FILE}"
set -e
DEVICE_PATH="${OBJROOT}/UninstalledProducts/${TARGET_NAME}.framework"
SIMULATOR_PATH="${SYMROOT}/../../../../Products/Debug-iphonesimulator/${TARGET_NAME}.framework"
ARCHIVE_PATH="${SRCROOT}/_Archive"
if [ "${CONFIGURATION}" = "Release" ]; then
if [ -d "${DEVICE_PATH}" ]; then
if [ -d "${SIMULATOR_PATH}" ]; then
rm -rf "${ARCHIVE_PATH}"
mkdir "${ARCHIVE_PATH}"
import Foundation
extension UIImage {
func fixOrientation() -> UIImage {
// No-op if the orientation is already correct
if self.imageOrientation == .Up { return self }
// We need to calculate the proper transformation to make the image upright.