Skip to content

Instantly share code, notes, and snippets.

View mjjimenez's full-sized avatar

Mark Jimenez mjjimenez

View GitHub Profile
@mjjimenez
mjjimenez / centeredRectInRect.m
Created October 28, 2013 04:37
Centers a rect within anoter rect
static __inline__ NSRect CenteredRectInRect(NSRect innerRect, NSRect outerRect)
{
#if CGFLOAT_IS_DOUBLE
innerRect.origin.x = outerRect.origin.x
+ floor((outerRect.size.width - innerRect.size.width) / (CGFloat) 2.0);
innerRect.origin.y = outerRect.origin.y
+ floor((outerRect.size.height - innerRect.size.height) / (CGFloat) 2.0);
#else
innerRect.origin.x = outerRect.origin.x
+ floorf((outerRect.size.width - innerRect.size.width) / (CGFloat) 2.0);
@mjjimenez
mjjimenez / quickdialog_viewcontroller.m
Created October 28, 2013 03:24
Use QuickDialog forms with a storyboard.
-(id) initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
QRootElement *_root = [[QRootElement alloc] init];
_root.grouped = YES;
/* Put your init code here or in viewDidLoad */
self.root = _root;
}
return self;
}
@mjjimenez
mjjimenez / child_view_frame.m
Created October 25, 2013 03:10
Set the frame of an inner/child view to be inside the parent view and define the left and right margins.
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 80.0f);
self.pageViewController.view.frame = pageViewRect;
@mjjimenez
mjjimenez / current_page.m
Created October 24, 2013 09:36
Get the current page of a UIScrollview
int page = scrollView.contentOffset.x / scrollView.frame.size.width;
#import <UIKit/UIKit.h>
@interface PRLabel : UILabel
@property (strong, nonatomic, readwrite) UIView* inputView;
@property (strong, nonatomic, readwrite) UIView* inputAccessoryView;
@end
@mjjimenez
mjjimenez / remove_cursor.m
Created October 24, 2013 06:53
Remove cursor from UITextField
//Subclass UITextfield and Override the - (CGRect)caretRectForPosition:(UITextPosition *)position //method and return CGRectZero.
- (CGRect)caretRectForPosition:(UITextPosition *)position {
return CGRectZero;
}
@mjjimenez
mjjimenez / datepicker_with_toolbar.m
Created October 24, 2013 06:35
Create date picker with accessory view and attach it to a uitextfield
- (void)viewDidLoad
{
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
UIToolbar *toolbar =[[UIToolbar alloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,44)];
toolbar.barStyle =UIBarStyleDefault;
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
@mjjimenez
mjjimenez / clear_textfield_button
Created October 23, 2013 11:16
Show "clear textfield" button on textfield
myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
@mjjimenez
mjjimenez / update_tableview_cell
Created October 23, 2013 06:00
Adjust tableview cell properties without reloading contents
[self.tableView beginUpdates];
[self.tableView endUpdates];
@mjjimenez
mjjimenez / add_refresh_control
Created October 18, 2013 15:25
Add UIRefreshControl to UICollectionView
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor grayColor];
[refreshControl addTarget:self action:@selector(refershControlAction) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];
self.collectionView.alwaysBounceVertical = YES;