How to check internet connection in iOS

Here is its usage:

if ([Connection isConnected]) {  ...  }
else {  ...  }
//
//  Connection.h
//  iBlog
//
//  Created by Ondrej Rafaj on 12.11.09.
//  Copyright 2009 Home. All rights reserved.
//
#import 
#import 
#import 
#import 
#import   

@interface Connection : NSObject {  

}  

+ (BOOL) isConnected;  

@end

Continue reading “How to check internet connection in iOS” »

Force change UI orientation

This method link a toggle function to change between lanscape to protrait

if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){ [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; }else{ [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; }

Reflexion in Objective-C

The simple way to create the new object with class name

id *object = [[NSClassFromString(@"MyClassName") alloc] init];

see also

NSGetSizeAndAlignment NSClassFromString NSStringFromClass NSSelectorFromString NSStringFromSelector NSStringFromProtocol NSProtocolFromString

How to add extra font to iOS

1. import font into xcode project 2. add UIAppFonts properties into info.plist with your file name of your font eg ‘filename.tlf’ 3. Use the font name like iOS font system

UIFont *font = [UIFont fontWithName: @"Font Name" size: 60]; _textLabel.font = font;

Adding background image to UINavigationBar

Create the class that override UINavigationBar and override drawRect function like this.

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
    UIColor *color = [UIColor orangeColor];
    UIImage *img  = [UIImage imageNamed: @"nav_bar.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.tintColor = color;
    [super drawRect: rect];
}

@end

Also, for the next we want to change text in the title
Continue reading “Adding background image to UINavigationBar” »