Objective:
In our iOS development process, if you know some special tips, in fact, can help you save a lot of things, of course, this thing does not need us to remember, it is estimated that no few developers like to memorize, there is a need, the Internet to find, learning while using the correct way to open the technique. After all, this thing is also a process of accumulating sums over time. Here summed up some of the usual accumulation of some of the development of small skills, in fact, there are some if you do not touch the problem I can not remember, so intend to continue to update, the small skills encountered a little summed up, it finally made a series. What you want to be good, welcome in the comments below to show you, we learn from each other.
One: Add rounded corners of individual directions to any control that inherits and UIView
UILabel * label = [[UILabel alloc]initwithframe:cgrectmake (+, +, +)]; Label.backgroundcolor = [Uicolor bluecolor]; CGRect rect = CGRectMake (0, 0,.); Cgsize size = Cgsizemake (ten); The position of the fillet uirectcorner corner = uirectcornertopleft; A method for adding rounded corners to a rectangle by a Bezier curve uibezierpath * Path = [Uibezierpath bezierpathwithroundedrect:rect byroundingcorners:corner Cornerradii:size]; Create Shaplayer cashapelayer * Masklayer = [[Cashapelayer alloc]init]; Masklayer.frame = label.bounds; Set path Masklayer.path = path. Cgpath; Label.layer.mask = Masklayer; [Self.view Addsubview:label];
The effect is as follows:
Two: The circle of Friends of this jump you pay attention to it?
You try to find a circle of friends in your circle of friends, click on the details, then click on the button like the number of likes or comments, and you'll see the flip effect.
Testviewcontroller * Con = [[Testviewcontroller alloc]init]; The following Modaltransitionstyle property is an enumeration type, defined in four ways /** typedef ns_enum (Nsinteger, Uimodaltransitionstyle) { uimodaltransitionstylecoververtical = 0,//Default Bottom-to-top uimodaltransitionstylefliphorizontal, //Flip uimodaltransitionstylecrossdissolve,//fade Uimodaltransitionstylepartialcurl,//page Flip }; Con.modaltransitionstyle = uimodaltransitionstylefliphorizontal; [Self Presentviewcontroller:con animated:yes completion:^{ }]; return to the usual dismiss [self dismissviewcontrolleranimated:yes completion:^{ }];
here is a flip-and-flip effect:
By the way give everyone a Mac-side GIF chart recording software: simple, rough licecap
Three: various customizations of textfile
The following is a simple example, such as the location of its hints and the color of the font, the effect is as follows:
Here are some of its methods, there are many in the textfile. h file, you can go to learn, as long as we inherit with Textfile, rewrite their corresponding method below:
Control where text is displayed-(CGRect) Textrectforbounds: (cgrect) bounds{ }//Control the location of the Clear button-(CGRect) Clearbuttonrectforbounds: ( CGRect) bounds{}//Control the location of the edit text-(CGRect) Editingrectforbounds: (cgrect) bounds{}//control placeholder position, left and right 20-(CGRect) Placeholderrectforbounds: (cgrect) bounds{ cgrect inset = CGRectMake (bounds.origin.x, bounds.origin.y+10, BOUNDS.SIZE.WIDTH-10, bounds.size.height); return inset;} Control placeholder Color font-(void) Drawplaceholderinrect: (cgrect) rect{ [[Uicolor Redcolor]setfill]; Nsmutabledictionary *attributes = [nsmutabledictionary dictionary]; Attributes[nsforegroundcolorattributename] = [Uicolor redcolor]; Attributes[nsfontattributename] = [Uifont systemfontofsize:14]; [Self.placeholder drawinrect:rect withattributes:attributes];}
Four: Summarize the property string:
/** * character attribute summary nsstring *const nsfontattributename; the font corresponds to a Uifont object nsstring *const nsparagraphstyleattributename; the corresponding value of the paragraph is a Nsparagraphstyle object NSString *const Nsforegroundcolorattributename; the value corresponding to the font color is a Uicolor object nsstring *const nsbackgroundcolorattributename; the font background color is also a Uicolor object NSString *const Nsligatureattributename; the hyphen nsstring *const nskernattributename; the corresponding value of the word spacing is a NSNumber object, default 0 nsstring *const Nsstrikethroughstyleattributename; The median line (a line in the middle of the string) corresponds to a NSNumber object, and the default value is Nsunderlinestylenone nsstring *const Nsunderlinestyleattributename; The underscore value is a NSNumber object nsstring *const nsstrokecolorattributename; Edge Color The corresponding value is a Uicolor object nsstring *const nsstrokewidthattributename; edge width The value that corresponds to this property is a NSNumber object NSString *const Nsshadowattributename; (shadow) the corresponding value of the layout is a Nsshadow object. The default is nil NSString *const nsverticalglyphformattributename; It works better with the shading above.
V: Slide gesture
In this case, if you are using the system return mode when you push to the next interface on the navigation bar, your app will support the slide gesture, you can try it yourself, but in many cases our return button will be customized. This time the system's slide gesture is not working, but the slide as an app is also a common user experience is a good thing, it is recommended that we add to the app to enhance our user experience.
The following code is written in the base class of your entire project to go if ([Self.navigationcontroller respondstoselector: @selector (Interactivepopgesturerecognizer) ] { //need to follow the gesture of proxy self.navigationController.interactivePopGestureRecognizer.delegate = self; self.navigationController.interactivePopGestureRecognizer.enabled = YES; }
here again this fdfullscreenpopgesture I think is also very good, a 0-line code of the three-way library, you need to do is to add it to the middle of your project is enough! Look at one of the effects of git on its display:
Six: You want to add a head view to your WebView
ScrollView inside is a uiwebbrowserview (responsible for displaying webview content), you can add a head to your webview by adjusting its position. UIView *webbrowserview = self. zxwebview.scrollview.subviews[0];//get webview Webbrowserview self.backheadimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, Self.view.bounds.size.width, self.view.bounds.size.height*2/3.0)]; [_backheadimageview sd_setimagewithurl:[nsurl URLWithString:self.imageUrl] placeholderimage:[uiimage imagenamed: @ "Placeholderimage"]; [_backheadimageview setimage:[uiimage imagenamed:@ "1.jpg"]; Insert the Backheadimageview into the WebView ScrollView below the//[self. Zxwebview Insertsubview:_backheadimageview belowsubview:self. Zxwebview.scrollview]; Add Backheadimageview to your WebView ScrollView, these two effects are different, you can try it yourself. [Self. Zxwebview.scrollview Addsubview:_backheadimageview]; Change the Webbrowserview frame down to the backheadimageview height so that it is visible cgrect frame = webbrowserview.frame; FRAME.ORIGIN.Y = Cgrectgetmaxy (_backheadimageview.frame); Webbrowserview.frame = frame; Load Web page [_zxwebview loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:@ "https://www.baidu.com"]];
Seven: TableView of the tail processing
TableView This we also have a common, such as you created the cell, you use 10, the rest will be blank but the cell will still exist in the form of the appearance, like the following, you feel very ugly, how to do?
This is actually very simple, you just need to deal with TableView's tail view, assign an initialized view to it OK.
-(void) viewdidload { [super viewdidload]; [Self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:@ "Reuseidentifier"]; Here to deal with, you can try to see the difference between this sentence and no. Self.tableView.tableFooterView = [[UIView alloc]init];} #pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {#warning Incomplete implementation, return the number of sections return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {#warning Incomplete Implementation, return the number of rows return 10;} -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath { UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:@ "Reuseidentifier" Forindexpath:indexpath]; Cell.textLabel.text = @ "Zhang Xu You bastard"; return cell;}
Eight: navigation bar those things
The navigation bar above those things, I first give you a link to summarize the comprehensive, specific knowledge of everyone just to see the contents of this link, we say little tricks, simple, how to set the navigation to transparent.
the above navigation is transparent, but its line is still in, this we can also hide, see the following two lines of code :
Set navigation transparency [Self.navigationController.navigationBar setbackgroundimage:[uiimage new] Forbarmetrics: Uibarmetricsdefault]; Hide the line below the navigation //self.navigationController.navigationBar.shadowImage = [UIImage new];
Also, the navigation of this piece, such as according to the sliding view below the sliding to change the transparency of the navigation, such as the use of the runtime to solve the problem, before the sky in the summary runtime has said how to do, interested friends can go to turn over, link here.
Nine: GCD writing a timer is actually very simple.
look at the following code automatic prompt, directly knocked up you do not need to write too much, but pay attention to your here. Time is written as a global variable or Dispatch_source_set_event_handler inside again to call your time.
dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0); This is just a delay effect, remember to write time as a global variable to prevent premature release under arc dispatch_source_t timer = dispatch_source_create (dispatch_source_type _timer, 0, 0, queue); Dispatch_source_set_timer (Timer, Dispatch_time_now, 1.0 * nsec_per_sec, 0 * nsec_per_sec); Dispatch_source_set_event_handler (timer, ^{ NSLog (@ "12321431234"); }); Dispatch_resume (timer);
Ten: Determine whether the interface is push or present appears
Here's not much to say, directly on the code
Nsarray *viewcontrollers=self.navigationcontroller.viewcontrollers;if (Viewcontrollers.count > 1) { if ([ Viewcontrollers Objectatindex:viewcontrollers.count-1] = = self) { //push mode [Self.navigationcontroller Popviewcontrolleranimated:yes];} } Else{//present Way [self dismissviewcontrolleranimated:yes completion:nil];}
11: No lock screen
This is more common, recently the company is also ready to do live streaming app, I believe this will certainly be used to;
[UIApplication sharedapplication].idletimerdisabled = yes;//or [[UIApplication sharedapplication] Setidletimerdisabled:yes];
Summarize common development techniques