IPhone Development notes and tips (1)

Source: Internet
Author: User
1) iPhone Program One way to achieve screenshot capture in the iPhone program: // import the header file # import quartzcore/quartzcore. h // set the entire self. create an image uigraphicsbeginimagecontext (self. view. bounds. size); [self. view. layer renderincontext: uigraphicsgetcurrentcontext ()]; uiimage * image = encrypt (); uigraphicsendimagecontext (); // Save the image to the image uiimagewritetosavedphotosalbum (image, self, nil, nil); 2) Objective-C Plot 1. color and font uikit provides the UI Color and uifont class to set the color and font, uicolor * redcolor = [uicolor redcolor]; [redcolor set]; // set to Red uifont * front = [uifont systemfontofsize: 14.0]; // obtain the system font [mylable setfont: font]; // set the font of the Text object. 2. drawrect Method for drawing, you first need to reload the drawrect method, and then call the setneedsdisplay method for the system to draw a picture:-(void) drawrect :( cgrect) rect; // draw a picture in the area specified by rect-(void) setneedsdisplay; // Let the system call drawrect to draw a picture. 3) latency function and timer usage latency function: [nsthread sleepfortimeinterval: 5.0]; // pause for 5S. use of Timer: nstimer * con Nectiontimer; // timer object // instantiate timerself. connectiontimer = [nstimerscheduledtimerwithtimeinterval: 1.5 target: selfselector: @ selector (timerfired :) userinfo: Nil repeats: No]; [[nsunloop currentrunloop] addtimer: Self. connectiontimer formode: nsdefaultrunloopmode]; // use timer as a latency method do {[[nsunloopcurrentrunloop] rununtildate: [nsdatedatewithtimeintervalsincenow: 1.0];} while (! Done); // timer calls the function-(void) timerfired :( nstimer *) timer {done plugin, and then places it in the resource of the xcode project. In the xxxappdelegate. M program, insert the following Code :-(Bool) Application :( uiapplication *) random :( nsdictionary *) launchoptions {//-inserta delay of 5 seconds before the splash screendisappears-[nsthread sleepfortimeinterval: 5.0]; // override point for customization after applicationlaunch. // Add the View Controller's view to the window anddisplay. [windowaddsubview: viewcontroller. view]; [windowmakekeyandvisible]; Return ye S;} the splash page disappears after 5 seconds. 5) Think about controller in iPhone development, there is only one window, which corresponds to multiple views, and the view is organized in various forms, the key is to rely on controllers to organize the logical relationships of various views. The general relationship is as follows: Form --- the main controller (such as the navigation Controller). The main controller is in the form and you can drag it in the past, write related variable code in appdelegate-there are other controllers under the master controller, such as the view controller, which can be associated with the Root View through interfacebuilder-The View Controller is equivalent to a Root View, you can call other views. The view contains class files (. H ,. m) and graphical interface file (. XIB) (the two must be associated .) 6) The page turning effect is often seen by the iPhone software turning up and down. In fact, this is very simple, and there are already encapsulated methods to deal with it. // First set the Animation Parameters [uiview beginanimations: @ "curl" context: Nil]; [uiview setanimationduration: 1.25]; // time [uiviewsetanimationcurve: uiviewanimationcurveeaseinout]; // speed // then set the animation action and target view [uiviewsetanimationtransition: uiviewanimationtransitioncurlup forview: Self. view cache: Yes]; The parameter uiviewanimationtransitioncurlup indicates turning up the page. If it is down, uiviewanimationtransitioncurldown. for view, the current view is passed in. // Final submit the animation [uiview commitanimations]; 7) Custom button uibutton * BTN; cgrect frame; BTN = [[uibutton buttonwithtype: uibuttontypecustom] retain]; // button type [BTN setimage: [uiimage imagenamed: @“aaa.png "] forstate: uicontrolstatenormal]; // set button image BTN. tag = 10; frame. size. width = 59; // set the width of the frame button. size. height = 59; // set the height frame of the button. origin. X = 150; // set the frame of the button. origin. y = 260; [BTN setframe: frame]; [BTN setbackgroundcolor: [uicolor clearcolor]; [BTN addtarget: Self action: @ selector (btnpressed :) forcontrolevents: uicontroleventtouchupinside]; // Click Event [self. view addsubview: BTN]; [BTN release];-(void) btnpressed :( ID) sender {// click event where the button is implemented} 8) capture the screen image // create a bitmap-based image context and specify the size as cgsizemake (200,400) uigraphicsbeginimagecontext (cgsizemake (200,400 )); // renderincontext presents the receiver and Its subrange to the specified context [self. view. layerrenderincontext: uigraphicsgetcurrentcontext ()]; // returns an image uiimage * aimage = uigraphicsgetimagefromcurrentimagecontext () based on the current image context (); // remove the image context uigraphicsendimagecontext () based on the current bitmap at the top of the stack; // return the imagedata = uiimagepngrepresentation (aimage) of the specified image in PNG format );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.