Skip to content

Instantly share code, notes, and snippets.

@dutran90
dutran90 / UIImagePickerView
Created August 28, 2015 11:52
UIImagePickerView
#pragma mark - UIPickerView Datasource
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return _clubNameArray.count;
}
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return _clubNameArray[row];
}
// Show actionsheet
NSString *actionSheetTitle = @"Add Photo"; //Action Sheet Title
NSString *other1 = @"Take Photo";
NSString *other2 = @"Choose from Gallery";
NSString *cancelTitle = @"Cancel";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
@dutran90
dutran90 / MyTextField.h
Created August 27, 2015 15:23
MyTextFiled padding
#import <UIKit/UIKit.h>
@interface MyTextField : UITextField
{
BOOL isEnablePadding;
float paddingLeft;
float paddingRight;
float paddingTop;
float paddingBottom;
}
@dutran90
dutran90 / Show&Hide Keyboard
Last active August 27, 2015 15:07
Show&Hide Keyboard
//ViewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
@dutran90
dutran90 / Autolayout Programming
Created August 18, 2015 16:11
Autolayout Programming
// Width constraint, half of parent view width
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerView
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeWidth
multiplier:0.5
constant:0]];
// Height constraint, half of parent view height
@dutran90
dutran90 / Design Pattern
Created August 18, 2015 16:05
Design Pattern
// SINGLETON PATTERN
-->.h:
+ (instancetype)sharedInstance;
-->.m:
+ (instancetype)sharedInstance
{
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyClass alloc] init];
@dutran90
dutran90 / UICollectionView
Created August 18, 2015 15:49
UICollectionView
#pragma mark - Process data
- (CGFloat) calculateWidthItem{
return ([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2;
}
- (CGFloat) calculateHeightItem{
return (([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2)*1.5;
}
--> widthItem = [self calculateWidthItem];
heightItem = [self calculateHeightItem];
@dutran90
dutran90 / MBHUDProgress
Created August 18, 2015 15:42
MBHUDProgress
// BASIC
MBProgressHUD *hud;
hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"loading...";
[hud show:YES];
--> [hud hide:YES];
@dutran90
dutran90 / AppDelegate
Created August 18, 2015 15:38
AppDelegate
// Call ViewController with UINavigationController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MainVC *vcMain = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vcMain];
self.window.rootViewController = nav;
nav.navigationBarHidden = YES;
return YES;
@dutran90
dutran90 / AFNetworking
Last active December 23, 2015 12:52
AFNetworking
//GET
+(void) checkLoginWithUsername:(NSString*)username andPassword:(NSString*)password InBackground:(void(^)(BOOL success)) completionHandler{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *para = [NSDictionary dictionaryWithObjectsAndKeys:username, @"email", password, @"password", nil];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"admin" password:@"admin"];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[manager GET:@"http://lottofy.gleblu.com/ws/login.php" parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([[responseObject objectForKey:@"success"] doubleValue] == 0) {
completionHandler(NO);