1. Set the deselected status when tableview returns
-(Void) Viewwillappear :(Bool) Animated
{
[Super Viewwillappear: Animated];
[Self.Tableview Deselectrowatindexpath:Self.Tableview.Indexpathforselectedrow Animated:Yes];
}
2. Set uipickerview to be selected by default.
[Pickerview Selectrow:5 Incomponent:0 Animated:No];
3. Set the color of the application battery bar.
[[Uiapplication sharedapplication] setstatusbarstyle: uistatusbarstyleblackopaque];
4. Check the network connection status (add systemconfiguration. Framework and reachability. h and reachability. m)
If(([Reachability Reachabilityforinternetconnection].Currentreachabilitystatus=Notreachable)&&
([Reachability Reachabilityforlocalwifi].Currentreachabilitystatus=Notreachable)){
Nslog (@ "No network connection ");
}
5. Image Scaling
Uiimage* Image = [[Uiimage Alloc]Initwithdata:Self.Activedownload];
If(Image.Size.Width! =Kappiconheight& Image.Size.Height! =Kappiconheight)
{
CgsizeItemsize =Cgsizemake(Kappiconheight,Kappiconheight);
Uigraphicsbeginimagecontext(Itemsize );
CgrectImagerect =Cgrectmake(0.0,0.0, Itemsize.Width, Itemsize.Height);
[ImageDrawinrect: Imagerect];
Self.Apprecord.Appicon=Uigraphicsgetimagefromcurrentimagecontext();
Uigraphicsendimagecontext();
}
Else
{
Self.Apprecord.Appicon= Image;
}
6. Set the uiwenview background to transparent
Webview. backgroundcolor = [uicolor clearcolor];
Webview. opaque = no;
Set in the webpage:
<Body style = "background-color: Transparent">
7. js controls uiwebvie
JS:
<SCRIPT>
Function jump ()
{
VaR clicked = true;
Window. Location = "/clicked"; // modify the URL. Note: use the "/" separator.
Alert ("JS alert: Jump ");
}
</SCRIPT>
OC:
-(Bool) Webview :(Uiwebview*) Webview shouldstartloadwithrequest :(Nsurlrequest*) Request navigationtype :(Uiwebviewnavigationtype) Navigationtype
{
//ObtainURLAnd compare to determine whether the triggerJSEvent. Note that"/"
If ([request. maindocumenturl . relativepath isw.tostring : @ "/clicked" ]) {
Uialertview* Alertview = [[Uialertview Alloc]Initwithtitle:@ "You click me" Message:@ "Clicked" Delegate:NilCancelbuttontitle:@ "Sure" Otherbuttontitles:@ "Cancel",Nil];
[AlertviewShow];
[AlertviewRelease];
Return False;
}
ReturnTrue;
}
8. uiwebview loading local HTML
- Nsstring * Path = [[nsbundle mainbundle] pathforresource :@"Index"Oftype :@"Html"];
- [Self. webview loadrequest: [nsurlrequest requestwithurl: [nsurl fileurlwithpath: path];
9. Set the uiwebview zoom factor
The uiwebview class does not have a method to modify the scaling factor. We can only use HTMLCode. You can set the viewport for the meta tag, and the viewport contains the parameter for initializing the scaling factor.
The meta tag is as follows:
<Meta name = "viewport" content = "minimum-scale = 0.6; maximum-scale = 5; initial-scale = 1; User-scalable = yes; width = 640">
The following parameters are available:
- Minimum-Scale:
The minimum allowed scaling factor. The default value is 0.25, and the allowed value is 0-10.
- Maximum-Scale:
The maximum number of running zooming. The default value is 1.6, and the allowed value is 0-10.
- Initial-Scale:
The default scaling factor before the web page is loaded and not scaled by the user. The default value is automatically calculated based on the page size and available area, but the value is between the minimum and maximum.
- User-scalable
Whether to scale the web page.
- Width:
The width of the viewpoint. Default Value: 980 pixels (iPhone ). The allowed value is 200-10000 ." Device-width indicates the device width (320 for iPhone and 768 for iPad ). Note that device width is not equal to the width of the user interface. The device width is always the width of the device in portrait mode (the screen direction is positive ). To increase the maximum scaling factor of a web page (1.6 by default), you only need to add the meta tag to the HTML code and specify the maximum-scale attribute. You can directly go to HTMLSource codeAdd the meta tag. If the web page is from the Internet and cannot modify the HTML source code, you can use JavaScript code to create a meta tag and attach it to the HTML code of the web page. After reading the rest of the content, you will know how to do it.
- Height:
The height of the viewport. It is usually calculated based on width.
10. Click the Home Key to trigger
-(Void) Applicationwillresignactive :(Uiapplication*) Application
11. Mutual conversion between nsdata and nsstring
Nsdata * xmldata = [@ "testdata" datausingencoding: nsutf8stringencoding];
Nsstring * result = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding];
12. Convert image to rounded corner
First import the header file:# Import<Quartzcore/quartzcore. h>
Uiimageview * headerimage = [[uiimageview alloc] initwithframe: cgrectmake (10.0, 10.0, 64.0, 64.0)];
Headerimage. Image = contactphoto;
Calayer * layer = [headerimage layer];
[Layer setmaskstobounds: Yes];
[Layer setcornerradius: 10.0];
[Layer setborderwidth: 1.0];
[Layer setbordercolor: [[uicolor blackcolor] cgcolor];
[Contactheader addsubview: headerimage];
13. Code for saving an image to an album
Uiimagewritetosavedphotosalbum(Uiimage,Nil,Nil,Nil);
14. Remove the tableview line.
[Self.Tableview Setseparatorstyle:Uitableviewcellseparatorstylenone];
15. Add shadow to uilable text
Titletext.Shadowcolor= [Uicolor Blackcolor];
Titletext.Shadowoffset=Cgsizemake(0,-1.0);
16. Convert the plist file to nsdictionary
Nsbundle* Bundle = [Nsbundle Mainbundle];
//Get File Path
Nsstring* Plistpath = [bundlePathforresource:@ "Citydata" Oftype:@ "Plist"];
//Read toNsdictionary
Citydictionary= [[Nsdictionary Alloc]Initwithcontentsoffile: Plistpath];
17. Hide tabbar
-(Void) Hidetabbar :(Bool) Hidden {
[Uiview Beginanimations:Nil Context:Null];
[Uiview Setanimationduration:0];
For(Uiview* ViewIn Self.Tabbarcontroller.View.Subviews)
{
If([ViewIskindofclass:[Uitabbar Class])
{
If(Hidden ){
[ViewSetframe:Cgrectmake(View.Frame.Origin.X,480, View.Frame.Size.Width, View.Frame.Size.Height)];
}Else{
[ViewSetframe:Cgrectmake(View.Frame.Origin.X,480-49, View.Frame.Size.Width, View.Frame.Size.Height)];
}
}
Else
{
If(Hidden ){
[ViewSetframe:Cgrectmake(View.Frame.Origin.X, View.Frame.Origin.Y, View.Frame.Size.Width,480)];
}Else{
[ViewSetframe:Cgrectmake(View.Frame.Origin.X, View.Frame.Origin.Y, View.Frame.Size.Width,480-49)];
}
}
}
[Uiview Commitanimations];
}