Monday, July 30, 2012

Customize view using XIB

This is the example of how to customize UITableViewCell using XIB.

1. Create your XIB:

2. Load XIB and create it as a view:

3. Done

Friday, July 27, 2012

Force using english localized if current localized does not exists

Create a class:

CLocale.h
#undef NSLocalizedString#define NSLocalizedString(key, comment) \
[CLocale localizedString:(key)]
@interface CLocale : NSObject
+ (NSString*) localizedString:(NSString*)key;
@end

CLocale.m
#import "CLocale.h"
@implementation CLocale
+ (NSString*) localizedString:(NSString*)key
{
    NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
    NSString* currentLocale = [languages objectAtIndex:0];
    NSString* localized = [[NSBundle mainBundle] localizedStringForKey:key value:@"" table:nil];
    // if key and localized are same, also it is not english,
    // then force to use english language
    if ([localized compare:key] == NSOrderedSame && [currentLocale compare:@"en"] != NSOrderedSame)
    {
        NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"]];
        localized = NSLocalizedStringFromTableInBundle(key, nil, bundle, nil);
    }
    return localized;
}
@end

At last, include it into your pre-defined header (.pch)
#import "CLocale.h"

Done.


[ROM] Samsung S7 Stock Firmware BRI (Taiwan台灣)

Latest ROM: G930FXXU1DQEU Download: https://kfhost.net/tpl/firmwares.php?record=B7E6DE774E3811E7963AFA163EE8F90B Reference: http://...