iOS Small method

Source: Internet
Author: User

1. Take a string in a string
[Plain] View plaincopyprint?
NSString *str [email protected]"12SADFSDF56AFSDF";
NSLog (@ "%@", str);
NSString *thrstr = [strstringbyreplacingoccurrencesofstring:@ "" withstring:@ "88"];
NSLog (@ "%@", thrstr);
That is, replace the 56 in 12SADFSDF56AFSDF with 88, and replace the string with the following: 12SADFSDF88AFSDF


2. Simple plist get
[plain] view plaincopyprint? 
NSString *path = [[Nsbundlemainbundle] pathforresource:@ "Array" oftype:@ "plist"];  
nsmutabledictionary *data = [[Nsmutabledictionaryalloc] initwithcontentsoffile:path];  
NSLog (@ "%d", [Datacount]);   
NSLog (@ "%@", [ Dataallvalues]);   
NSLog (@ "------------");    
Nsarray *ary = [dataallkeys]; 
NSLog (@ "%d", [Arycount]);  
Nsarray *array = [nsarrayarraywitharray:ary];   
for (int i =0;i<[arraycount];i++)    
{   
    nslog (@ "\ n value = %@ ", [arrayobjectatindex:i]);     
}   
Nsarray *getarray = [[ Dataallvalues]objectatindex:5];

NSLog (@ "get_array:%@", GetArray);

3. The status bar and Uinavigationbar are set to transparent
[[Uiapplicationsharedapplication]setstatusbarstyle:uistatusbarstyleblacktranslucent]; The status bar is set to transparent
TheNavigationController.navigationBar.barStyle =uibarstyleblacktranslucent; Set Navigationbar to Transparent


4. Set object fillet, such as UIView, Uiimageview, etc.
A few simple steps:
I. Import the QUARTZCORE.FRAMEWORK framework #import
Two. Object.layer.maskstobounds=yes;
Three. Object.layer.cornerradius=xxx;
[Plain] View plaincopyprint?
Uiimageview *testimageview = [[uiimageviewalloc]initwithimage:[uiimageimagenamed:@ "1.jpg"]];
[Testimageviewsetframe:cgrectmake (20,20,100,100)];
TestImageView.layer.masksToBounds =yes;
TestImageView.layer.cornerRadius =50/2; Set the angle to change the viewing effect
TestImageView.layer.borderWidth = 5; Border width
TestImageView.layer.borderColor = [Uicoloryellowcolor].   Cgcolor; Border color
[Self.viewaddSubview:testImageView];
[Testimageviewrelease];

5. The setup screen is lit when the program is in the boot state
UIApplication *appdelegate = [Uiapplicationsharedapplication];
Appdelegate.idletimerdisabled =yes;


6. Set UITableViewCell to display sub-headings  
when initializing: cell = [[Uitableviewcellalloc]initwithstyle: uitableviewcellstylesubtitlereuseidentifier:cellidentifier]; 
The style should be noted here, which is set to show sub-heading styles, and the default style is not to display sub-headings, which are available after Setup: &NBSP
Cell.detailTextLabel.text [email protected] "detailed label";     set sub-headings


7. Set the shadow effect   for UIView;
[plain] view plaincopyprint? 
UIView *showview = [[ Uiviewalloc]initwithframe:cgrectmake (10,150,100,100)];   
Showview.backgroundcolor = [ uicolorredcolor];  
ShowView.layer.shadowOffset =cgsizemake (15,5);    
ShowView.layer.shadowOpacity =0.6;   
ShowView.layer.shadowColor = [Uicolorblackcolor]. cgcolor;  
[self.viewaddsubview:showview];   
[showviewrelease];  


8. Set the location of the UITableView selected lines  
[self.tableviewselectrowatindexpath:[ nsindexpathindexpathforrow:5insection:0]animated:noscrollposition:uitableviewscrollpositionmiddle];   
//selectrowatindexpath Sets the number of rows and section   scrollposition settings to scroll to (4 items to choose from)


9.UITextField agent for each operation call, can be changed according to requirements
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string
{
nsmutablestring *newstring = [[Textfield.textmutablecopy]autorelease];
[NewStringreplaceCharactersInRange:rangewithString:string]; The string that gets changed
}


10. How to generate UIImage with Uicolor

[Plain] View plaincopyprint?
-(void) viewdidload
{
[Superviewdidload];
Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (10,10,100,100)];
UIImage *image = [self createimagewithcolor:[uicoloryellowcolor]; Create a picture of a yellow color
[Imageviewsetimage:image];
[Self.viewaddSubview:imageView];
[Imageviewrelease];
}
-(UIImage *) Createimagewithcolor: (Uicolor *) color
{
CGRect rect = CGRectMake (0.0f,0.0f,1.0f,1.0f);
Uigraphicsbeginimagecontext (rect.size);
Cgcontextref context =uigraphicsgetcurrentcontext ();
Cgcontextsetfillcolorwithcolor (context, [colorcgcolor]);
Cgcontextfillrect (context, rect);
UIImage *theimage =uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return theimage;
}


This article is from the "zhuoking" blog, make sure to keep this source http://9951038.blog.51cto.com/9941038/1827817

iOS Small method

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.