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 FILE_NAME @"CONFIG" | |
#define FILE_TYPE @"plist" | |
// eg: cName shanghai | |
+ (void)setDefultCity:(NSString *)cName | |
{ |
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
Class itemClass = [MKMapItem class]; | |
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { | |
// iOS 6 MKMapItem available | |
MKPlacemark* place = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lng) addressDictionary:nil]; | |
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:place]; | |
destination.name = addrName; | |
NSArray *items = @[destination]; | |
NSDictionary* options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}; | |
[MKMapItem openMapsWithItems:items launchOptions:options]; | |
} else { |
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
// 产生随机数种子 | |
srandom((unsigned)time(NULL)); | |
- (CGPoint)randomPoint | |
{ | |
CGPoint result; | |
NSRect r = [self bounds]; | |
result.x = r.origin.x + random()%(int)r.size.width; | |
result.y = r.origin.y + random()%(int)r.size.height; | |
return result; |
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
cd到相应目录,在终端中输入下面两个命令,输出结果相加 | |
find ./ -name "*.m" -exec cat {} \; |wc -l | |
find ./ -name "*.h" -exec cat {} \; | wc -l |
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 UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] | |
// from http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string |
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
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]]; | |
[titleBarAttributes setValue:navBarTitleColor forKey:UITextAttributeTextColor]; | |
[titleBarAttributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.f, 0.f)] forKey:UITextAttributeTextShadowOffset]; | |
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes]; | |
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]]; | |
[[UINavigationBar appearance] setTintColor:kNAVIGATIONBAR_BARBUTTON_COLOR]; | |
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: | |
[UIColor blackColor], | |
UITextAttributeTextColor, |
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
// 从上往下落的动作 (MKMapViewDelegate method) | |
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views | |
{ | |
CGRect visibleRect = [mapView annotationVisibleRect]; | |
for (MKAnnotationView *view in views) { | |
CGRect endFrame = view.frame; | |
CGRect startFrame = endFrame; | |
startFrame.origin.y = visibleRect.origin.y - startFrame.size.height; | |
view.frame = startFrame; | |
[UIView beginAnimations:@"drop" context:NULL]; |
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]) | |
{ |
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
// 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"; |
OlderNewer