Skip to content

Instantly share code, notes, and snippets.

@DwightChan
DwightChan / LayoutableButton.swift
Created July 19, 2017 09:39 — forked from gbitaudeau/LayoutableButton.swift
I created a UIButton subclass whose purpose is to be able to choose where the button's image is layout, either vertically or horizontally. See http://stackoverflow.com/a/41744464/1661338
// Created by Guillaume BITAUDEAU on 19/01/2017.
// @see : http://stackoverflow.com/a/41744464/1661338
import UIKit
@IBDesignable
class LayoutableButton: UIButton {
enum VerticalAlignment : String {
@DwightChan
DwightChan / NSString+UsefulShit.h
Created October 14, 2016 12:36 — forked from dsibilly/NSString+UsefulShit.h
Objective-C category demonstration
//
// NSString+UsefulStuff.h
//
// Duane Sibilly <[email protected]>
// 6/21/11
// Copyright (c) 2011-2012 Duane Sibilly. All rights reserved.
#import <Foundation/Foundation.h>
// The use of the parenthesis in the interface declaration is what tells the
@DwightChan
DwightChan / UIView+ModifyFrame.h
Created October 14, 2016 12:36 — forked from bobmoff/UIView+ModifyFrame.h
Simple but really useful category on UIView that makes modifying the frame NOT hellish. Published under WTFPL [http://www.wtfpl.net/]. Usage example can be found in the comments
/*
Before:
CGRect frame = myView.frame;
frame.origin.x = newX;
myView.frame = frame;
After:
myView.x = newX;
@DwightChan
DwightChan / CGRect+Additions.h
Created October 14, 2016 12:36 — forked from aegzorz/CGRect+Additions.h
Some functions for dealing with CGRects
static __inline__ CGRect CGRectFromCGSize( CGSize size ) {
return CGRectMake( 0, 0, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithCenterAndSize( CGPoint center, CGSize size ) {
return CGRectMake( center.x - size.width * 0.5, center.y - size.height * 0.5, size.width, size.height );
};
static __inline__ CGRect CGRectMakeWithOriginAndSize( CGPoint origin, CGSize size ) {
return CGRectMake( origin.x, origin.y, size.width, size.height );
@DwightChan
DwightChan / NSArray+FirstObject.h
Created October 14, 2016 12:35 — forked from aegzorz/NSArray+FirstObject.h
Gets the first object in an array or returns nil for empty array.
//
// NSArray+FirstObject.h
//
#import <Foundation/Foundation.h>
@interface NSArray (FirstObject)
- (id)firstObject;
@DwightChan
DwightChan / NSString+Extensions.h
Created October 14, 2016 12:35 — forked from Abeansits/NSString+Extensions.h
A utility box for NSStrings. Converts to: SHA1, NSNumber. Test for being empty. Contains substrings and replace substrings from NSDictionary.
#import <Foundation/Foundation.h>
@interface NSString (Extensions)
+ (NSString *)stringToSha1:(NSString *)str;
- (NSNumber*)stringToNSNumber;
- (BOOL)isEmpty;
- (BOOL)stringContainsSubString:(NSString *)subString;
- (NSString *)stringByReplacingStringsFromDictionary:(NSDictionary *)dict;
@DwightChan
DwightChan / UILabel+dynamicSizeMe.h
Created October 14, 2016 12:33 — forked from danielphillips/UILabel+dynamicSizeMe.h
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end
@DwightChan
DwightChan / MKMapView+MoveLogo.h
Created October 14, 2016 12:33 — forked from maciekish/MKMapView+MoveLogo.h
This category allows you to move the MKMapView logo so that it remains visible if you put other stuff on the mapview. If the logo is hidden, the app won't pass the App Store review. Tested with iOS 5 through 7.
//
// MKMapView+MoveLogo.h
//
// Created by Maciej Swic on 2013-07-08.
// Released under the MIT license.
//
// This category allows you to move the MKMapView logo so that it remains visible if you
// put other stuff on the mapview. If the logo is hidden, the app won't pass the App Store
// review. Tested with iOS 5 through 7.
//
@DwightChan
DwightChan / UIView+Stacker.h
Created October 14, 2016 12:33 — forked from bobmoff/UIView+Stacker.h
Stack subviews vertically ordered by their index. Good when u want to use XIB's and need to layout views (show/hide) based on external data, but cannot use autolayout.
#import <UIKit/UIKit.h>
@interface UIView (Stacker)
- (void)stackSubviews;
@end
@DwightChan
DwightChan / UIView+RoundedCorners.h
Created October 14, 2016 12:33 — forked from bobmoff/UIView+RoundedCorners.h
Add rounded corners to any view using layer mask.
#import <UIKit/UIKit.h>
@interface UIView (RoundedCorners)
- (void)setRoundedCorners:(UIRectCorner)corners radius:(CGSize)size;
@end