Created
March 29, 2013 05:25
-
-
Save ayakix/5268928 to your computer and use it in GitHub Desktop.
Utility and Tips for iPhone programming ref: http://qiita.com/items/fcccf652fd51a2f9b010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(UIColor*) hexToUIColor:(NSString *)hex | |
{ | |
if(hex.length == 6) | |
hex = [@"FF" stringByAppendingString: hex]; | |
NSScanner *colorScanner = [NSScanner scannerWithString:hex]; | |
unsigned int color; | |
[colorScanner scanHexInt:&color]; | |
CGFloat a = ((color & 0xFF000000) >> 24)/255.0f; | |
CGFloat r = ((color & 0x00FF0000) >> 16)/255.0f; | |
CGFloat g = ((color & 0x0000FF00) >> 8) /255.0f; | |
CGFloat b = (color & 0x000000FF) /255.0f; | |
return [UIColor colorWithRed:r green:g blue:b alpha:a]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(CGFloat)screenWidth | |
{ | |
CGRect r = [[UIScreen mainScreen] bounds]; | |
return r.size.width; | |
} | |
+(CGFloat)fullScreenHeight | |
{ | |
CGRect r = [[UIScreen mainScreen] bounds]; | |
return r.size.height; | |
} | |
+(CGFloat)screenHeight | |
{ | |
CGRect r = [[UIScreen mainScreen] applicationFrame]; | |
return r.size.height; | |
} | |
+(CGFloat)statusBarHeight | |
{ | |
CGRect full = [[UIScreen mainScreen] bounds]; | |
CGRect main = [[UIScreen mainScreen] applicationFrame]; | |
return full.size.height - main.size.height; | |
} | |
+(CGFloat)navigationBarHeight | |
{ | |
// Use this method in ViewController >> [[[self tabBarController] rotationgHeaderView] frame].size.height; | |
return 44.0; | |
} | |
+(CGFloat)tabBarHeight | |
{ | |
// Use this method in ViewController >> [[[self tabBarController] rotationgFooterView] frame].size.height; | |
return 49.0; | |
} | |
+(CGFloat)contentHeight | |
{ | |
return [LayoutUtil screenHeight] - [LayoutUtil navigationBarHeight]; | |
} | |
+(CGFloat)contentY | |
{ | |
return [LayoutUtil statusBarHeight] + [LayoutUtil navigationBarHeight]; | |
} | |
+(BOOL)isAspectRatio3x2 | |
{ | |
return ([LayoutUtil fullScreenHeight] / [LayoutUtil screenWidth] == 3.0 / 2.0); | |
} | |
+(CGFloat)screenScale | |
{ | |
return ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) ? [[UIScreen mainScreen] scale] : 1.0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIView*)getGoogleLogo | |
{ | |
NSArray *subviews = [self subviews]; | |
if (subviews && [subviews count] < 2) return nil; | |
UIView *logoView = [[self subviews] objectAtIndex:1]; | |
if ([logoView isKindOfClass:[UIImageView class]] != YES) return nil; | |
if (logoView.frame.size.width != 69 || logoView.frame.size.height != 23) return nil; | |
return logoView; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _(key) NSLocalizedString(key, key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CGFloat)sX | |
{ | |
return self.frame.origin.x; | |
} | |
- (CGFloat)sY | |
{ | |
return self.frame.origin.y; | |
} | |
- (CGFloat)width | |
{ | |
return self.frame.size.width; | |
} | |
- (CGFloat)height | |
{ | |
return self.frame.size.height; | |
} | |
- (CGFloat)eX | |
{ | |
return self.frame.origin.x + self.frame.size.width; | |
} | |
- (CGFloat)eY | |
{ | |
return self.frame.origin.y + self.frame.size.height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment