Skip to content

Instantly share code, notes, and snippets.

View psobko's full-sized avatar

Piotrek Sobkowski psobko

View GitHub Profile
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
//H
@interface UITextField(UITextFieldCategory) {
}
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)textRectForBounds:(CGRect)bounds;
@end
//M
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
UITextPosition *beginning = [textField beginningOfDocument];
[textField setSelectedTextRange:[textField textRangeFromPosition:beginning
toPosition:beginning]];
}
XCTFail (format…)
XCTAssertNil (a1, format…)
XCTAssertNotNil (a1, format…)
XCTAssert (a1, format…)
XCTAssertTrue (a1, format…)
XCTAssertFalse (a1, format…)
XCTAssertEqualObjects (a1, a2, format…)
XCTAssertEquals (a1, a2, format…)
XCTAssertEqualsWithAccuracy (a1, a2, accuracy, format…)
XCTAssertThrows (expression, format…)
typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space @ . prominently).
@psobko
psobko / Custom_UITableViewCell
Created October 21, 2013 17:02
Custom UITableViewCell
static NSString *cellIdentifier = @"SomeCell";
QRScanCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SomeCellNib"
owner:self
options:nil];
cell = [nib lastObject];
}
@psobko
psobko / UITableViewCell_Seprator
Created October 21, 2013 17:04
UITableViewCell Seperator
//Remove seperator insets on iOS7
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
//Set a custom cell seperator
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
...
@psobko
psobko / NStimer
Created October 21, 2013 18:43
NSTimer
//Setup
NSTimer *aTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f
target:self
selector:@selector(someSelector)
userInfo:nil
repeats:YES];
//Tear down
[aTimer invalidate];
aTimer = nil;
@psobko
psobko / UITextField leftView UIImageView padding
Created October 26, 2013 18:53
UITextField padding with a custom leftView UIImageView
-(UIView*)paddingViewWithImage:(UIImageView*)imageView andPadding:(float)padding
{
float height = CGRectGetHeight(imageView.frame);
float width = CGRectGetWidth(imageView.frame) + padding;
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[paddingView addSubview:imageView];
return paddingView;
@psobko
psobko / Preprocessor Macros
Created October 28, 2013 17:09
Preprocessor Macros
//http://www.tutorialspoint.com/cprogramming/c_preprocessors.htm
#define Substitutes a preprocessor macro
#include Inserts a particular header from another file
#undef Undefines a preprocessor macro
#ifdef Returns true if this macro is defined
#ifndef Returns true if this macro is not defined
#if Tests if a compile time condition is true
#else The alternative for #if
#elif #else an #if in one statement