Skip to content

Instantly share code, notes, and snippets.

View psobko's full-sized avatar

Piotrek Sobkowski psobko

View GitHub Profile
@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 / 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 / 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 / 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];
}
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).
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…)
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
UITextPosition *beginning = [textField beginningOfDocument];
[textField setSelectedTextRange:[textField textRangeFromPosition:beginning
toPosition:beginning]];
}
//H
@interface UITextField(UITextFieldCategory) {
}
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)textRectForBounds:(CGRect)bounds;
@end
//M
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
@psobko
psobko / 0_reuse_code.js
Created September 27, 2013 21:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console