What to Know: 22 tricky tricks for iOS development
Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p><p><p>Combined with their own practice development experience summed up the 22 iOS development tips, with a very happy tone to easily solve the development process encountered a variety of hardship problems, light reading has been laughing.</p></p><p><p><strong>1. What if the TableView does not display a cell with no content?</strong></p></p><p><p>Similar to Figure 1, I don't want to let those empty displays BELOW. Very simple, Add "self.tableView.tableFooterView = [[UIView alloc] init];" Try to say yes, after adding this sentence has become the Figure 2 Appearance.</p></p><p><p><strong>2. What do I do if I customize the Leftbarbuttonitem left slide return gesture to fail?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">Self.navigationItem.leftBarButtonItem = [[uibarbuttonitem alloc]</li> <li>Initwithimage:img</li> <li class="alt">Style:uibarbuttonitemstyleplain</li> <li>Target:self</li> <li class="alt">Action:<span class="annotation">@selector (onback:)];</span></li> <li>Self.navigationController.interactivePopGestureRecognizer.delegate = (id<uigesturerecognizerdelegate>) Self ;</li> </ol> </ol><p><p><strong>3. ScrollView inexplicable can't viewcontroller to the top of the row?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">Self.automaticallyadjustsscrollviewinsets = NO;</li> </ol> </ol><p><p><strong>4. Keyboard Event Write well irritable, all want to fall keyboard what to do?</strong></p></p><p><p>Buy a sturdy keyboard;<br>use iqkeyboardmanager (can be searched on github), The waist does not ache after use, the leg also is not sour.</p></p><p><p>5. Why my app is always not fluent, what is the problem?</p></p><p><p></p></p><p><p></p></p><p><p>This artifact is called: kmcgeigercounter, go to GitHub to carry it.</p></p><p><p>6. How to adjust the position of separaline without creating a new cell?</p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">_mytableview.separatorinset = Uiedgeinsetsmake (<span class="number">0, <span class="number">0, <span class="number"> <span class="number">0);</span> </span> </span> </span></li> </ol> </ol><p><p>7. How to click Self.view to let the keyboard, need to add a tapgestures?</p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">-(<span class="keyword">void) touchesbegan: (nsset *) touches withevent: (uievent *) event</span></li> <li>{</li> <li class="alt">[self.view endediting:yes];</li> <li>}</li> </ol> </ol><p><p><strong>8. How to set the default background image for each viewcontroller?</strong></p></p><p><p>Use the base class ah, Juvenile.</p></p><p><p><strong>9. Want to change in the code to add the Layoutattributes in the xib, but how to use the code to find?</strong></p></p><p><p>Pull the button like pull your restraint, Nslayoutattribute also can pull the Line.</p></p><p><p><strong>10. How to hide navigationbar when sliding like safari?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">Navigationcontroller.hidesbarsonswipe = Yes</li> </ol> </ol><p><p><strong>11. Navigation bar Return key The title of the belt is too annoying, how to let it disappear?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">[[uibarbuttonitem appearance] setbackbuttontitlepositionadjustment:uioffsetmake (<span class="number">0,-<span class="number">)</span> </span></li> <li>forbarmetrics:uibarmetricsdefault];</li> </ol> </ol><p><p><strong>CoreData used to be very annoying, grammar and smelly and long how to do?</strong></p></p><p><p>Magicrecord</p></p><p><p><strong>How does CollectionView implement Tableview's hover header?</strong></p></p><p><p>Csstickyheaderflowlayout</p></p><p><p><strong>14. Can I use only one pan gesture in place of the uiswipegesture in all directions?</strong></p></p> <ol class="dp-j"> <li class="alt"><li class="alt">-(<span class="keyword">void) pan: (uipangesturerecognizer *) Sender</span></li></li> <li><li>{</li></li> <li class="alt"><li class="alt">typedef ns_enum (nsuinteger, Uipangesturerecognizerdirection) {</li></li> <li><li>uipangesturerecognizerdirectionundefined,</li></li> <li class="alt"><li class="alt">uipangesturerecognizerdirectionup,</li></li> <li><li>uipangesturerecognizerdirectiondown,</li></li> <li class="alt"><li class="alt">uipangesturerecognizerdirectionleft,</li></li> <li><li>Uipangesturerecognizerdirectionright</li></li> <li class="alt"><li class="alt">};</li></li> <li><li><span class="keyword">static Uipangesturerecognizerdirection Direction = uipangesturerecognizerdirectionundefined;</span></li></li> <li class="alt"><li class="alt"><span class="keyword">Switch (sender.state) {</span></li></li> <li><li><span class="keyword">Case Uigesturerecognizerstatebegan: {</span></li></li> <li class="alt"><li class="alt"><span class="keyword">if (direction = = Uipangesturerecognizerdirectionundefined) {</span></li></li> <li><li>Cgpoint velocity = [sender velocityInView:recognizer.view];</li></li> <li class="alt"><li class="alt">BOOL isverticalgesture = fabs (velocity.y) > Fabs (velocity.x);</li></li> <li><li><span class="keyword">If (isverticalgesture) {</span></li></li> <li class="alt"><li class="alt"><span class="keyword">If (velocity.y > <span class="number">0) {</span></span></li></li> <li><li>Direction = uipangesturerecognizerdirectiondown;</li></li> <li class="alt"><li class="alt">} <span class="keyword">Else {</span></li></li> <li><li>Direction = uipangesturerecognizerdirectionup;</li></li> <li class="alt"><li class="alt">}</li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">else {</span></li></li> <li><li><span class="keyword">If (velocity.x > <span class="number">0) {</span></span></li></li> <li class="alt"><li class="alt">Direction = uipangesturerecognizerdirectionright;</li></li> <li><li>} <span class="keyword">Else {</span></li></li> <li class="alt"><li class="alt">Direction = uipangesturerecognizerdirectionleft;</li></li> <li><li>}</li></li> <li class="alt"><li class="alt">}</li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uigesturerecognizerstatechanged: {</span></li></li> <li><li><span class="keyword">Switch (direction) {</span></li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uipangesturerecognizerdirectionup: {</span></li></li> <li><li>[self handleupwardsgesture:sender];</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uipangesturerecognizerdirectiondown: {</span></li></li> <li><li>[self handledownwardsgesture:sender];</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uipangesturerecognizerdirectionleft: {</span></li></li> <li><li>[self handleleftgesture:sender];</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uipangesturerecognizerdirectionright: {</span></li></li> <li><li>[self handlerightgesture:sender];</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">default: {</span></li></li> <li><li><span class="keyword">Break</span></li></li> <li class="alt"><li class="alt">}</li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Case Uigesturerecognizerstateended: {</span></li></li> <li><li>Direction = uipangesturerecognizerdirectionundefined;</li></li> <li class="alt"><li class="alt"><span class="keyword">Break</span></li></li> <li><li>}</li></li> <li class="alt"><li class="alt"><span class="keyword">Default</span></li></li> <li><li><span class="keyword">Break</span></li></li> <li class="alt"><li class="alt">}</li></li> <li><li>}</li></li> </ol><p><p>15. How can I stretch the picture so that it doesn't deform?</p></p><p><p>Method One:</p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">UIImage *image = [[UIImage imagenamed:@<span class="string">"xxx"] stretchableimagewithleftcapwidth:<span class="number">topcapheight: ten<span class="number">];</span> </span></span></li> </ol> </ol><p><p>Note: developers are reminded that this has been deprecated, now the method is called Resizableimagewithcapinsets.</p></p><p><p><strong>Method two,</strong></p></p><p><p></p></p><p><p><strong>16. How to play gif when this card, there is no better library?</strong></p></p><p><p>Flipboard's Flanimatedimage is perfect for you.</p></p><p><p><strong>17. How to add a pull-up refresh in a sentence?</strong></p></p><p><p>Using the Svpulltorefresh library:</p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">[tableView addpulltorefreshwithactionhandler:^{</li> <li><span class="comment">prepend data to dataSource, insert cells at top of table view</span></li> <li class="alt"><span class="comment">Call [tableview.pulltorefreshview stopanimating] when done</span></li> <li>} position:svpulltorefreshpositionbottom];</li> </ol> </ol><p><p><strong>18. How do I change the color of the TableView cell to another color?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">_mtableview.tintcolor = [uicolor redcolor];</li> </ol> </ol><p><p><strong>19. Originally my statusbar is lightcontent, The result uses Uiimagepickercontroller will cause my statusbar's style to turn black, how to do?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">-(<span class="keyword">void) navigationcontroller: (uinavigationcontroller *) navigationcontroller willshowviewcontroller: ( Uiviewcontroller *) viewcontroller animated: (BOOL) animated</span></li> <li>{</li> <li class="alt">[[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent];</li> <li>}</li> </ol> </ol><p><p><strong>20. How do I make my navigationbar transparent rather than blurry?</strong></p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">[self.navigationbar setbackgroundimage:[uiimage <span class="keyword">new]</span></li> <li>forbarmetrics:uibarmetricsdefault];</li> <li class="alt">Self.navigationBar.shadowImage = [UIImage <span class="keyword">new];</span></li> <li>Self.navigationBar.translucent = YES;</li> </ol> </ol><p><p><strong>21. How to change the color and position of Uitextfield placeholder?</strong></p></p><p><p>Inherit uitextfield, overriding this method:</p></p> <ol class="dp-j"> <ol class="dp-j"> <li class="alt">-(<span class="keyword">void) drawplaceholderinrect: (cgrect) rect {</span></li> <li>[[uicolor bluecolor] setfill];</li> <li class="alt">[self.placeholder drawinrect:rect WithFont:self.font linebreakmode:uilinebreakmodetailtruncation alignment: self.textalignment];</li> <li>}</li> </ol> </ol><p><p><strong>22. Why do you know so many strange tricks?</strong></p></p><p><p>Go stack Overflow brush problem ah, teenager!</p></p><p><p>What to Know: 22 tricky tricks for iOS development</p></p></span>
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