Objective-C – How to use member variables in the categories.

.h

@interface UIView (ObjectTagAdditions)
@property (nonatomic, retain) id objectTag;
@end

.m

#import <objc/runtime.h>
static char const * const ObjectTagKey = "ObjectTag";

@implementation UIView (ObjectTagAdditions)
@dynamic objectTag;

- (id)objectTag {
    return objc_getAssociatedObject(self, &ObjectTagKey);
}

- (void)setObjectTag:(id)newObjectTag {
    objc_setAssociatedObject(self, &ObjectTagKey, newObjectTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Cited from : http://oleb.net/blog/2011/05/faking-ivars-in-objc-categories-with-associative-references/

Convert yyyy-MM-ddTHH:mm:ss.SSSZ format to default timezone

– (NSDate *) localDateStringForISODateTimeString:(NSString *) anISOString

{
NSDateFormatter *isoDateFormatter = [[NSDateFormatter alloc] init];
[isoDateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”];
[isoDateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@”UTC”]];

NSDateFormatter *userFormatter = [[NSDateFormatter alloc] init];
[userFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@”UTC”]];

NSDate *date = [isoDateFormatter dateFromString:anISOString];
return [dateFormatter dateFromString:[userFormatter stringFromDate:date]];
}

iOS orientation animation does not happen smoothly

If you apply any changes to the layer of underlying view.

for example,

shadowImageView.layer.masksToBounds = NO;
shadowImageView.layer.shadowOffset = CGSizeMake(-5, 0);
shadowImageView.layer.shadowOpacity = 1.0;

iOS custom UDID

UIImagePickerController is shifted by ~20px

Subclass UIImagePickerController and override

- (BOOL)  shouldAutorotate
{
return NO;
}