iOS Development Basics-Fragmentation 12

Source: Internet
Author: User
Tags uikit

1:delegate Application

. h#import <UIKit/UIKit.h> @protocol filterheaderviewdelegate <NSObject> @required-(void) Filterheaderviewmorebtnclicked: (ID) sender; @endextern float cylfilterheaderviewheigt; @interface Filterheaderview: Uicollectionreusableview@property (nonatomic, weak  ) id<filterheaderviewdelegate> delegate; @end. m (void) Morebtnclicked: (ID) Sender {    if ([Self.delegate respondstoselector: @selector (filterheaderviewmorebtnclicked:)] ) {        [self.delegate FilterHeaderViewMoreBtnClicked:self.moreButton];    }} Note that in. m there will be a call to the above method: [Self.morebutton addtarget:self Action: @selector (morebtnclicked:) forControlEvents: UIControlEventTouchUpInside]; while calling this plugin, remember to assign delegate to self and introduce filterheaderviewdelegate into <> And then you can implement this deletage method;

2: Realize UIButton display in different state

[Btn settitle:@ "more" forstate:uicontrolstatenormal];    [Btn settitle:@] "forstate:uicontrolstateselected";    Btn.titleLabel.font = [Uifont systemfontofsize:12];    [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal];    [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstateselected];    btn.adjustsimagewhenhighlighted = NO;    [Btn setimage:[uiimage imagenamed:@ "Home_btn_more_normal"] forstate:uicontrolstatenormal];    [Btn setimage:[uiimage imagenamed:@ "home_btn_more_selected"] forstate:uicontrolstateselected];    Btn.titleedgeinsets = Uiedgeinsetsmake (0,-btn.imageview.frame.size.width-kimagetotextmargin, 0, Btn.imageView.frame.size.width);    Btn.imageedgeinsets = Uiedgeinsetsmake (0, btn.titleLabel.frame.size.width, 0,-btn.titlelabel.frame.size.width);

3: View UIView Add Click event

    if (!_ticketview) {        _ticketview=[uiview new];        _ticketview.backgroundcolor=[uicolor Whitecolor];        Add Click event        uitapgesturerecognizer *tapgesture=[[uitapgesturerecognizer alloc] initwithtarget:self action:@ Selector (tickaction:)];        [_ticketview addgesturerecognizer:tapgesture];        [_belowview Addsubview:_ticketview];    } Call:-(void) Tickaction: (ID) sender{    NSLog (@ "SDFSDFSDF");}

4: Scrolling View Uiscrollview incompatibility problem in iOS7, unable to scroll

Place the definition of contentsize in viewdidlayoutsubviews;-(void) viewdidlayoutsubviews{    _myscrollview.contentsize=cgsizemake (screen_width,600);}

5: Flip the icon on the UIButton

#define Degrees_to_radians (angle) ((angle)/180.0 *m_pi) Call: _btnmorecontent.imageview.transform = Cgaffinetransformrotate (_btnmorecontent.imageview.transform, Degrees_to_radians (180));

6: Create a background picture and load it dynamically from the network

In Viewdidload call:-(void) loadbackviewimage{    uiimageview *bgview=[[uiimageview alloc] Initwithframe:cgrectmake (0, 0, Screen_width, screen_height)];        Bgview.image=[uiimage imagenamed:@ "Bgweatherempty"];        [Bgview sd_setimagewithurl:[nsurl URLWithString:self.backImageUrl] placeholderimage:[uiimage imagenamed:@ " Bgweatherempty "] completed:^ (UIImage *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {        Dispatch_async (Dispatch_get_main_queue (), ^{            bgview.image=image;            [Self.view Addsubview:bgview];            [Self.view Sendsubviewtoback:bgview];}        ;    }];} Note: UIView hierarchy Management (sendsubviewtoback,bringsubviewtofront) displays a uiview in front of the Bringsubviewtofront () method that only needs to call its parent view. Pushing a uiview layer to the back only requires calling its parent view's Sendsubviewtoback () method.

7: Load Xib into other views

Create a UIView xib file, this equation can look at any article on the Internet, mainly to the property of the custom class assigned to the creation of the. h file;. h#import <UIKit/UIKit.h> @interface Lktextview:uiview@property (Strong, nonatomic) Iboutlet UILabel *lbtext;-(ibaction) bt_pressed: (ID) sender; @property ( Strong, Nonatomic) Iboutlet Uitextfield *textview;+ (lktextview*) Instancetextview; @end. M#import "LKTextView.h" # Import "RKTabView.h" #import "RKTabItem.h" @implementation lktextview@synthesize TextView; @synthesize lbtext;+ ( Lktextview *) instancetextview{nsarray* nibview = [[NSBundle mainbundle] loadnibnamed:@ "Lktextview" Owner:nil options:    NIL]; return [Nibview objectatindex:0];}    -(ID) Initwithcoder: (Nscoder *) adecoder{self = [super Initwithcoder:adecoder];            if (self) {//The other one wants to add to the view of the [initviews]; } return self;} /** * @author Wujunyang, 15-04-30 16:04:03 * * @brief This is the Rktabview (void) */-to create a label initviews{UIView    Alloc] Initwithframe:cgrectmake (0, 0, 20, 30)];  Vi.backgroundcolor=[uicolor Redcolor];  [Self addsubview:vi];    Rktabview *titledtabsview=[[rktabview alloc] Initwithframe:cgrectmake (0, 0, 200, 50)];        [Self addsubview:titledtabsview]; Rktabitem *mastercardtabitem = [Rktabitem createusualitemwithimageenabled:nil imagedisabled:[uiimage imageNamed:@]    MasterCard "];    mastercardtabitem.titlestring = @ "MasterCard"; Rktabitem *paypaltabitem = [Rktabitem createusualitemwithimageenabled:nil imagedisabled:[uiimage imageNamed:@ "PayPal    "]];    paypaltabitem.titlestring = @ "PayPal";    Rktabitem *visatabitem = [Rktabitem createusualitemwithimageenabled:nil imagedisabled:[uiimage imageNamed:@ "Visa"];    visatabitem.titlestring = @ "Visa";    Rktabitem *wutabitem = [Rktabitem createusualitemwithimageenabled:nil imagedisabled:[uiimage imageNamed:@ "WU"];    wutabitem.titlestring = @ "Western Union"; Rktabitem *wiretabitem = [Rktabitem createusualitemwithimageenabled:nil imagedisabled:[uiimage imageNamed:@]    Wire-transfer "]; wiretabitem.titlestring = @ "Wire Transfer";        Mastercardtabitem.tabstate = tabstateenabled;    Titledtabsview.darkensbackgroundforenabledtabs = YES;    Titledtabsview.horizontalinsets = Horizontaledgeinsetsmake (25, 25);        Titledtabsview.titlesfontcolor = [Uicolor colorwithwhite:0.9f alpha:0.8f]; Titledtabsview.tabitems = @[mastercardtabitem, Paypaltabitem, Visatabitem, Wutabitem, WireTabItem];}  /*//only override drawrect:if your perform custom drawing.//an empty implementation adversely affects performance during animation.-(void) DrawRect: (cgrect) rect{//Drawing code}*/-(ibaction) bt_pressed: (ID) Sender {lbtext.text = Textvi Ew.text;}    @end then call the view. m:-(void) viewdidload{lktextview* text = [Lktextview Instancetextview];    Text.frame = CGRectMake (Text.frame.size.width, text.frame.size.height);   Text.textView.text = @ "Input";    [Self.view Addsubview:text];    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.}

8: Nice plug-in

AutoLayout automatic calculation of uitableviewcell height extension Fdtemplatelayoutcell    https://github.com/forkingdog/ Uitableview-fdtemplatelayoutcell switching between multi-view controllers--xlpagertabstrip                              https://github.com/xmartlabs/ Xlpagertabstrip Nice tab Plugin                                                 Https://github.com/RafaelKayumov/RKTabView
Generate @3x images for @2x and @1x versions--rtimageassets https://github.com/rickytan/RTImageAssets
Use: To generate @3x of the image resources corresponding to the @2x and @1x version, as long as drag high-definition map to the location of @3x, and then press Ctrl+shift+a to automatically generate two low-clear fill empty. Of course you can also generate the @3x version from the @2x map, if you are not good at the picture quality requirements

9:ios7 and iOS8 about the navigation bar.

The view in Uiviewcontroller in previous versions of iOS7 is automatically adjusted to remove the height of the navigation bar when displayed, and controls are automatically placed below the navigation bar. The Wantsfullscreenlayout attribute Uiviewcontroller in iOS7 is discarded, and all Uiviewcontroller are created by default So if some of the controls in the app interface with the navigation bar are covered by the navigation bar. Solution: You can use the iOS7 uiviewcontroller new properties Extendlayoutincludesopaquebars and Edgesforextendedlayout to resolve. This property specifies whether an attempt is made to extend to the area of bar when the bar is using an opaque picture, and the default value is No. And Edgesforextendedlayout This property specifies whether the view extends to the area of bar when the bar is using an opaque picture, the default value is No. And edgesforextendedlayout is to indicate whether the view covers the area of four weeks, the default is Uirectedgeall, that is, the upper and lower left and right four directions will be overwritten, so that the top does not extend to the area covered by the navigation bar, we can extend the top area to remove. The implementation code is as follows: Self.extendedlayoutincludesopaquebars = No;self.edgesforextendedlayout = Uirectedgebottom | Uirectedgeleft | Uirectedgeright;

11:initwithnibname/awakefromnib/initwithcoder Differences

First, Initwithnibname This method is created in the Controller's class in IB, but it is used when instantiating a controller through Xcode. Second, Initwithcoder is called when a class is created in IB but is instantiated in XOCDE. For example, create a controller's nib file with IB and then in Xcode Initwithnibname to instantiate the controller, the controller's initwithcoder will be called. Or a view nib file, similar to when the method is created, call Initwithcoder third, Awakefromnib when the. nib file is loaded, a awakefromnib message is sent to each object in the. nib file, and each object can define its own awakefromnib function to respond to the message and perform some necessary actions. That is, when you create a view object from a nib file, the Awakefromnib IV, the differences and linkages between Initwithnibname and loadnibnamed: About Initwithnibname and loadnibnamed System. I think I'm a little confused about what I'm going to do with the two. Actually figuring out the difference between them will not be so confused.  Because these two methods are not tarred with at all.  Since it is to illustrate these 2 methods, then focus on the difference.  But the first step is to wordy, their connection: You can use this method to load the user interface (Xib file) into our code, so that you can manipulate the loaded (Xib) object to operate the Xib file content. Enter the topic below to talk about the difference: 1. Showviewcontroller Initwithnibname Method Showviewcontroller * showmessage = [[Showviewcontroller alloc] initWithNibName:@  "Showviewcontroller" Bundle:nil];  Self.showviewcontroller = ShowMessage;  [ShowMessage release]; 2.VideoCellController loadnibnamed Method Nsarray * nib = [[NSBundle mainbundle] loadnibnamed:@ "Save3viewcontroller "Owner:self Options:nil];  Self.showviewcontroller = [nib Lastobject];  [NIB objectatindex:0]; Summary: Just look at their initialization, it may feel the same. But if, open to see the relationship between Xib, only to realize that their integration classes are different.  1. Initwithnibname the class of xib to be loaded for the view controller class that we have defined for US 2. Load mode different Initwithnibname method: is lazy loading, the control on this view is nil, only if need to display, will not nil  Loadnibnamed method: Instant loading, each element in the Xib object loaded with this method already exists. (Carefully understand this rule: when using loadNibNamed:owner:options:, the File's owner should is NSObject, the main view should be your class Type, and all outlets should is hooked up to the view, not the File ' Owner. ' Fifth, Initwithcoder and initWithFrame differences nitwith Oder is called when an object is loaded from the nib file, such as when your view is from the nib, then this function of the view is called.  (called by the Framework) initWithFrame (which is called by the user to initialize the object)

Basics of iOS development-fragmentation

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.