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 / 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 / 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 / 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 / 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 / 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 / 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 / CustomBackButton.m
Created June 12, 2015 09:58
Custom Back Button And Swipe Back. The only nice way I found to actually completely override the back button is to set the leftBarButtonItem, but then the swipe back gesture breaks. Luckily it's an easy fix when you know how
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:img
style:UIBarButtonItemStylePlain
target:self
action:@selector(onBack:)];
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
@ThinhPhan
ThinhPhan / SaveImageToFile.m
Last active August 29, 2015 14:23
Save image object to file.
// Reference links:
// https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/TechniquesforReadingandWritingCustomFiles/TechniquesforReadingandWritingCustomFiles.html
// http://stackoverflow.com/questions/7651632/how-to-speed-up-saving-a-uiimagepickercontroller-image-from-the-camera-to-the-fi
// http://www.codedisqus.com/0zJVUVqgPj/objectivec-uiimagewritetosavedphotosalbum-asynchronous-problems.html
// http://stackoverflow.com/questions/14411369/when-i-am-using-uiimagepngrepresentation-or-uiimagejpegrepresentation-for-conver?rq=1
// Save multi files async for saving time
- (void)saveUploadImages:(NSMutableArray *)images {
NSMutableArray *imagePaths = [[NSMutableArray alloc] init];
@ThinhPhan
ThinhPhan / ConvertImageToBase64String.m
Last active July 22, 2023 07:16
Convert Image to Base64 string
// Ref: http://stackoverflow.com/questions/11251340/convert-image-to-base64-string-in-ios-swift
// iOS7 > version for Objective-C
// You can use NSData's base64EncodedStringWithOptions
// Now encode as:
- (NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
@ThinhPhan
ThinhPhan / UIImage+SimpleResize.h
Created June 18, 2015 08:07
UIImage category for resizing
// UIImage+SimpleResize.h
//
// Created by Robert Ryan on 5/19/11.
#import <Foundation/Foundation.h>
/** Image resizing category.
*
* Modified by Robert Ryan on 5/19/11.
*