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
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]]; | |
NSArray *fontNames; | |
NSInteger indFamily, indFont; | |
for (indFamily=0; indFamily<[familyNames count]; ++indFamily) | |
{ | |
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]); | |
fontNames = [[NSArray alloc] initWithArray: | |
[UIFont fontNamesForFamilyName: | |
[familyNames objectAtIndex:indFamily]]]; | |
for (indFont=0; indFont<[fontNames count]; ++indFont) |
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)heighWithFont:(UIFont *)font constrainedToSize:(CGSize)size | |
{ | |
return [self sizeWithFont:font constrainedToSize:size].height; | |
} | |
- (CGFloat)widthWithFont:(UIFont *)font constrainedToSize:(CGSize)size | |
{ | |
return [self sizeWithFont:font constrainedToSize:size].width; | |
} |
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
// remove | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
if ([fileManager fileExistsAtPath:cachePath isDirectory:YES]) { | |
connsuccess = [fileManager removeItemAtPath:cachePath error:nil]; | |
} | |
// size bytes | |
- (unsigned long long)sizeForPath:(NSString *)path | |
{ | |
__block unsigned long long size = 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
// - (void)viewDidAppear | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(textFieldTextDidChangeNotification:) | |
name:UITextFieldTextDidChangeNotification | |
object:nil]; | |
// - (void)viewDidDisappear | |
[[NSNotificationCenter defaultCenter] removeObserver:self | |
name:UITextFieldTextDidChangeNotification | |
object:nil]; |
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
// 截全屏 | |
- (UIImage *)imageWithScreenContents | |
{ | |
UIGraphicsBeginImageContext(SCREEN_SIZE); | |
UIImage *aImage =UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return aImage; | |
} |
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
+ (int)countWord:(NSString *)s | |
{ | |
int i,n=[s length],l=0,a=0,b=0; | |
unichar c; | |
for(i=0;i<n;i++){ | |
c=[s characterAtIndex:i]; | |
if(isblank(c)){ | |
b++; | |
}else if(isascii(c)){ | |
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
+ (NSString *)dirUserData:(NSString *)userid | |
{ | |
NSArray *arrayFiles = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *docPath = [arrayFiles objectAtIndex:0]; | |
NSString *userDataDir = [docPath stringByAppendingPathComponent:userid]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
BOOL isDirectory; | |
BOOL isExist = [fileManager fileExistsAtPath:userDataDir isDirectory:&isDirectory]; | |
if (!isExist || (isExist && !isDirectory)) { | |
NSError *error; |
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
// Easiest way: | |
// Prefs.h | |
#define PREFS_MY_CONSTANT @"prefs_my_constant" | |
// Better way: | |
// Prefs.h | |
extern NSString * const PREFS_MY_CONSTANT; | |
// Prefs.m | |
NSString * const PREFS_MY_CONSTANT = @"prefs_my_constant"; |
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
static dispatch_once_t predicate; | |
+ (id)sharedUser | |
{ | |
static id shareUser = nil; | |
dispatch_once(&predicate, ^{ | |
shareUser = [[super allocWithZone:NULL] init]; | |
}); | |
return shareUser; | |
} |
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
// iOS4.0以上 | |
// MessageUI.framework | |
// #import <MessageUI/MessageUI.h> | |
// @interface ViewController () <MFMessageComposeViewControllerDelegate> | |
- (IBAction)sendSMS:(id)sender | |
{ | |
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init]; | |
if([MFMessageComposeViewController canSendText]) | |
{ |
NewerOlder