iOS Tips for beginner
2013年7月16日
ネットサーフィングしながらかき集めたTIPS.
いつか誰かの役に立つはず。(自分含む)
- Open an URL in Safari
- Hide the status bar
- Dial a Phone Number (iPhone Only)
- Launch the Apple Mail
- stop responding to touch events
- active the touch events
- Show the network Activity Indicator
- Hide the network Activity Indicator
- Prevents iPhone goes into sleep mode
- Display an alert window
- Get the path to the Documents folder
- Push another view controller onto the Navigation Bar
- Fade away a UIView by animating the alpha down to 0
- Get the name of the app
- Change the status bar to black
- Save a NSString into NSUserDefaults
- Check to make sure an objects support a method before calling it
- Log the name of the class and function
- Open Google Maps app with directions between two lat/long points
- Save bool to User Defaults
- Copy a file from x to y
- Screen touches method
- Get documents directory
- Load URL
- Get Current Date and time
- Quartz draw arc
- Make the device vibrate
- Open the Messages app with a specific phone number
- Stop responding to touch events
- Start responding again
- single line of code browser
- Change the title on the back button on a UINavigationView. Use this code on the UINavigationController before pushing the view
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/"]];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9662256888"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://mymail@myserver.com"]];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES; [UIApplication sharedApplication].applicationIconBadgeNumber = 10;
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"Warning" message:@"too many alerts" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; [alert show]
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* documentsDirectory = [paths objectAtIndex:0];
[self.navigationController pushViewController:anotherVC animated:YES];
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; // fade away over 1 seconds [aView setAlpha:0]; [UIView commitAnimations];
self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; Change the style of the navigation bar (from in a view controller): self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:loginName forKey:kUserLoginName]; Get an NSString from NSUserDefaults: NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; NSString* loginName = [defaults stringForKey:kUserLoginName];
if ([item respondsToSelector:@selector(activateBOP:)]) { [item activateBOP:closeBOP]; }
NSLog(@"%s", __PRETTY_FUNCTION__); Add rounded corners and/or a border around any UIView item (self) self.layer.borderColor = [UIColor whiteColor]. self.layer.cornerRadius = 8; // rounded corners self.layer.masksToBounds = YES; // prevent drawing outside border
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=d", start.latitude, start.longitude, finish.latitude, finish.longitude]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Yes Bool"];
[[NSFileManager defaultManager] copyItemAtPath:x toPath:y error:nil]; 1 <li>Display a new view</li> 1 [self presentModalViewController:(UIViewController *) animated:YES];
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0];
[MyWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://couleeapps.hostei.com"]]];
NSCalendar *gregorian = [NSCalendar currentCalendar]; NSDateComponents *dateComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:[NSDate date]]; Own enum type: typedef enum { a = 0, b = 1, c = 2 } enumName;
CGContextRef ctxt = UIGraphicsGetCurrentContext(); CGContextAddArc(ctxt, x, y, radius, startDeg, endDeg);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:123456789"]];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [urlText stringValue]]]];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil]; self.navigationItem.backBarButtonItem = backBarButtonItem; [backBarButtonItem release];
Have your say
You must be logged in to post a comment.