Skip to content

Instantly share code, notes, and snippets.

@amudi
amudi / UILabel+Striketrough.m
Created December 15, 2010 06:16
[iOS] UILabel+Striketrough
- (void)drawRect:(CGRect)rect {
if (self.text && [self.text length] > 0) {
CGContextRef context = UIGraphicsGetCurrentContext();
[self.textColor set];
[self.text drawInRect:rect withFont:self.font];
CGContextSetStrokeColorWithColor(context, self.textColor.CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextMoveToPoint(context, CGRectGetMinX(rect), CGRectGetMidY(rect));
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMidY(rect));
@amudi
amudi / prefix.pch
Created December 15, 2010 06:19
[iOS] logging macro for Objective-C
#ifdef __OBJC__
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#endif
@amudi
amudi / UIApplication+NetworkActivityIndicator.m
Created January 13, 2011 06:33
[iOS] centralized network activity indicator counter
@interface UIApplication (NetworkActivityIndicator)
- (void)increaseActiveRequests;
- (void)decreaseActiveRequests;
@end
@implementation UIApplication (NetworkActivityIndicator)
static int counter = 0;
@amudi
amudi / iOS UDID
Created January 17, 2011 09:58
[iOS] return UDID as NSString
+ (NSString *)UDIDString {
NSString *udid = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)[[UIDevice currentDevice] uniqueIdentifier],
NULL,
(CFStringRef)@" !*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
return [udid autorelease];
}
@amudi
amudi / AddressBookImage.m
Created January 20, 2011 08:39
[iOS] Get address book thumbnail if the method is available. Should weakly link the framework.
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *allAddressBookPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
for (int i = 0; i < [allAddressBookPeople count]; ++i) {
ABRecordRef record = [allAddressBookPeople objectAtIndex:i];
NSData *imageData = nil;
if (ABPersonCopyImageDataWithFormat != NULL) {
imageData = (NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail);
} else {
imageData = (NSData *)ABPersonCopyImageData(record);
}
@amudi
amudi / SharedPreferencesName.java
Created February 17, 2011 10:22
[Android] get SharedPreferences name from its resource id
public static String getSharedPreferenceName(Context ctx, int prefResId) {
String packageName = ctx.getApplicationContext().getPackageName();
Resources res = ctx.getResources();
String entryName = res.getResourceEntryName(prefResId);
return packageName + "_" + entryName;
}
@amudi
amudi / gist:943667
Created April 27, 2011 03:27
[iOS] UITableView content inset
[tableView setContentInset:UIEdgeInsetsMake(1, 0, 0, 0)]; // set content inset so the first separator is displayed
@amudi
amudi / AccordionTableView.m
Created April 5, 2012 03:04
Snippet of AccordionTableView logic
@synthesize selectedIndexPath;
@synthesize defaultRowHeight;
@synthesize optionRowHeight;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.optionRowHeight = 40;
}
@amudi
amudi / UIImage+RoundedResize.h
Created April 5, 2012 03:06
Some useful UIImage category method
//
// UIImage+RoundedResize.h
//
// Created by Amudi SEBASTIAN
//
#import <Foundation/Foundation.h>
@interface UIImage (RoundedResize)
Pod::Spec.new do |s|
s.name = "MPFlipViewController"
s.version = "0.0.2"
s.summary = "Container view controller (iOS 5 containment API) that navigates between child view controllers via touch gestures and page-flip animations."
s.description = "A custom container view controller following the iOS 5 containment API that navigates between child view controllers via touch gestures and page-flip animations."
s.homepage = "http://markpospesel.com/2012/07/28/mpflipviewcontroller/"
s.license = { :type => 'Modified BSD License', :file => 'Source Code License.rtf' }
s.author = "Mark Pospesel"
s.source = { :git => "https://github.com/amudi/MPFlipViewController.git", :commit => "815705bb46ee412b8d0d380c7eb8f07710b9b926" }
s.platform = :ios, '5.0'