Skip to content

Instantly share code, notes, and snippets.

View ThinhPhan's full-sized avatar
🎯
Focusing

Thinh Phan ThinhPhan

🎯
Focusing
View GitHub Profile
@ThinhPhan
ThinhPhan / register-push-notification.m
Created June 10, 2015 07:18
Register Push Notification on Xcode 5 and Xcode 6.
// A compile-time check is what you need in the case of Xcode 5
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
// use registerUserNotificationSettings
// Register for Push Notitications - iOS 8 Notifications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
@ThinhPhan
ThinhPhan / KeyboardHandle.m
Created June 2, 2015 15:48
Easy way to handle keyboard hide textfields in iOS
#pragma mark - Managing Keyboard
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
@ThinhPhan
ThinhPhan / UIColor+AppName.h
Created June 1, 2015 17:09
UIColor category for app
//
// UIColor+AppName.h
// AppName
//
// Created by Thinh Phan on 4/10/15.
// Copyright (c) 2015 Gennova. All rights reserved.
//
// See http://blog.alexedge.co.uk/speeding-up-uicolor-categories/
#define AGEColorDefine(COLOR_NAME) \
@ThinhPhan
ThinhPhan / white-status-bar.m
Last active August 29, 2015 14:22
Change status bar into white color in iOS 7/8 in a view controller.
1. Set navigation bar style to black
[self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
2. Set directly
- Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.
- In the viewDidLoad do a
[self setNeedsStatusBarAppearanceUpdate];
- Add the following method:
@ThinhPhan
ThinhPhan / md5.m
Created May 28, 2015 08:30
md5 a string
- (NSString *)md5:(NSString *)string {
// Create pointer to the string as UTF8
const char *ptr = [string UTF8String];
// Create byte array of unsigned chars
unsigned char md5Buffer[CC_MD5_DIGEST_LENGTH];
// Create 16 byte MD5 hash value, store in buffer
CC_MD5(ptr, strlen(ptr), md5Buffer ); // This is the md5 call
@ThinhPhan
ThinhPhan / List-All-Fonts-iOS-ObjC.m
Created May 18, 2015 01:52
Get list all available fonts in iOS
Objective-C
- (void)getListAvailableFontNames {
for (NSString *familyName in [UIFont familyNames]){
NSLog(@"Family name: %@", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"--Font name: %@", fontName);
}
}
}
@ThinhPhan
ThinhPhan / numberic-check.m
Created May 8, 2015 15:31
Check a string is a number or not
- (BOOL)isNumeric:(NSString *)string
{
NSScanner *scanner = [NSScanner scannerWithString:string];
return [scanner scanInteger:NULL] && [scanner isAtEnd];
}
@ThinhPhan
ThinhPhan / NSArray+JSONString.h
Created April 26, 2015 18:40
Category for get JSON string from NSDictionary, and NSData.
//
// NSArray+JSONString.h
//
//
// Created by Thinh Phan on 4/26/15.
// Copyright (c) 2015 Gennova. All rights reserved.
//
@interface NSArray (JSONString)
- (NSString *) jsonStringWithPrettyPrint:(BOOL)prettyPrint;
@ThinhPhan
ThinhPhan / ios-locale-identifiers.csv
Last active October 17, 2015 04:12 — forked from jacobbubu/ioslocaleidentifiers.csv
Country code in iOS
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Locale Country
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
@ThinhPhan
ThinhPhan / project-prefix.pch
Created April 8, 2015 07:59
Xcode Project-prefix Debug Log
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."