DiscussionIPhone DevelopmentCommon Code listing is the content to be introduced in this article.Iphone DevelopmentLet's talk about some common content. Let's take a look at the details first.
UIEdgeInsets sets the coordinates of tableView
- typedef struct UIEdgeInsets {
- CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
- } UIEdgeInsets;
It contains the upper, left, bottom, and right surround length. When you drag down, if top 0, it will be displayed. If it is less than 0, it will be hidden.
Returns the length of a string.
- CGSize detailSize = [@ "your string" sizeWithFont: [UIFont systemFontOfSize: 15]
- ConstrainedToSize: CGSizeMake (200, MAXFLOAT) lineBreakMode: UILineBreakModeWordWrap];
The back key of navigationbar triggers other events.
- UIButton * back = [[UIButton alloc] initWithFrame: CGRectMake (200, 25, 63, 30)];
- [Back addTarget: self act
- Ion: @ selector (reloadRowData :) forControlEvents: UIControlEventTouchUpInside];
- [Back setImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateNormal];
- UIBarButtonItem * backButtonItem = [[UIBarButtonItem alloc] initWithCustomView: back];
- Self. navigationItem. leftBarButtonItem = loginButtonItem
- [Back release];
- [BackButtonItem release];
Prevent the screen from being dimmed
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Network Activity Status Indicator
This is a rotating icon displayed in the status bar on the upper left of the iPhone, indicating that a network activity occurs on the background.
- UIApplication* app = [UIApplication sharedApplication];
- app.networkActivityIndicatorVisible = YES;
Obtain UUID
- [[UIDevice currentDevice] uniqueIdentifier]
-
- UIDevice *myDevice = [UIDevice currentDevice];
- NSString *deviceID = [myDevice uniqueIdentifier];
Screenshot
- UIGraphicsBeginImageContext (CGSizeMake (200,400); // create a bitmap-based image context and specify the size of CGSizeMake (200,400)
- [Self. view. layer renderInContext: UIGraphicsGetCurrentContext ()]; // renderInContext presents the receiver and Its subrange to the specified context.
- UIImage * aImage = UIGraphicsGetImageFromCurrentImageContext (); // returns an image based on the current image context.
- UIGraphicsEndImageContext (); // remove the graph context based on the current bitmap at the top of the stack.
- ImageData = UIImagePNGRepresentation (aImage); // return the data of the specified image in png format
Application border size
We should use "bounds" to obtain the application border. Instead of "applicationFrame ". "ApplicationFrame" also contains a 20-pixel status bar. Unless we need the extra 20-pixel status bar.
Vibrate and sound playback
- Sound will work in the Simulator, however some sound (such as looped) has been
- reported as not working in Simulator or even altogether depending on the audio format.
- Note there are specific filetypes that must be used (.wav in this example).
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- SystemSoundID pmph;
- id sndpath = [NSBundle mainBundle] pathForResource:@"mySound" ofType:@"wav" inDirectory:@"/"];
- CFURLRef baseURL = (CFURLRef) [NSURL alloc] initFileURLWithPath:sndpath];
- AudioServicesCreateSystemSoundID (baseURL, &pmph);
- AudioServicesPlaySystemSound(pmph);
- [baseURL release];
Iphone obtains the local IP Address
- -(NSString *)getAddress {
- char iphone_ip[255];
- strcpy(iphone_ip,"127.0.0.1"); // if everything fails
- NSHost* myhost =[NSHost currentHost];
- if (myhost)
- {
- NSString *ad = [myhost address];
- if (ad)
- strcpy(iphone_ip,[ad cStringUsingEncoding:NSASCIIStringEncoding]);
- }
- return [NSString stringWithFormat:@"%s",iphone_ip];
- }
Summary:IPhone DevelopmentThe list of frequently-used code has been introduced. I hope this article will help you!