Ios_6_toolbar+xib+ Dream of Red mansions

Source: Internet
Author: User

Finally




BeyondViewController.h

  beyondviewcontroller.h//  6_toolbar////  Created by Beyond on 14-7-24.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller-( ibaction) AddClick: (Uibarbuttonitem *) sender;-(ibaction) Removeclick: (Uibarbuttonitem *) sender; @property (Weak, nonatomic) Iboutlet Uibarbuttonitem *trashitem;//is dragged from the Xib interface, provided that the file ' s owner is the current controller class in the Setup interface, and that when the nib is loaded into the code, Also indicate that owner is an instance object of the current controller class, generally write self or empty-(ibaction) Deletebtnclick: (UIButton *) sender;-(ibaction) Headbtnclick: (UIButton * ) Sender; @end


Beyondviewcontroller.m

beyondviewcontroller.m//6_toolbar////Created by Beyond on 14-7-24.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" #import "RowView.h" #define krowhight 65//Classes Extension class extension    Also known as anonymous category @interface Beyondviewcontroller () {///member, array, composed of names Nsarray *_array_name; The index of the array value, and the name of the image, int _index;}    @end @implementation beyondviewcontroller-(void) viewdidload{[Super Viewdidload]; _array_name [email protected][@ "Lin Daiyu", @ "Xue Bao Chai", @ "Miaoyu", @ "Shi Xiangyun", @ "Spring", @ "Ching Wen", @ "nana"];_index = 0;} -(Ibaction) AddClick: (Uibarbuttonitem *) Sender {//Call own definition method, create a line through code Rowview//UIView *rowview = [Self Createrowvie        Wbycoding];        Call yourself to define a method, create a line through Xib rowview UIView *rowview = [self createrowviewbyxcodeinterfacebuilding];        Call yourself to define the method, return a Rowview instance object through the Rowview class method//UIView *rowview = [self createrowviewbyxib];    3, add to the current controller view [Self.view Addsubview:rowview];       5, animation effect [UIView animatewithduration:0.2 animations:^{ The following three steps are OC Standard Code, because OC does not agree to directly repair the object in the structure of the member of the property's value, to pass the middle of the temporary structural body variable cgrect frame = Rowview.frame;        frame.origin.x = 0;        Rowview.frame=frame;    Rowview.alpha = 1;    } completion:^ (BOOL finished) {///4, the Set Delete button is available _trashitem.enabled = YES; }];} Create a line with Xib rowview,xib <--> nib IPA <-->apk-(UIView *) createrowviewbyxib{//If you add the last one to the array, start from the beginning by adding the IF (_index >= _array_name.count)    {_index = 0;     }//below first calculate 3 parameters, picture name, name, Rowview to display the frame's y-coordinate nsstring *imgname = [NSString stringwithformat:@ "%d.png", _index];    NSString *labelname = _array_name[_index];    The Y value of the newly added row depends on the y + height + 1 UIView *lastview = Self.view.subviews.lastObject of the last child control in the view;        CGFloat rowy = lastview.frame.origin.y + lastview.frame.size.height+1; Call the class method, return a created rowview rowview *rowview = [Rowview rowviewwithheadname:imgname andlabelname:labelname AndRowY:rowY]        ;    Prepare _index++ for the next join line; return Rowview;} Create a row with Xib Rowview,xib <--> nib IPA <-->apk-(UIView *) createrowviewbyxcodeinterfacebuilding{//Mainbundel load xib, extension not written. Xib o When Wner is nil, manual addtarget, if it is an instance object of class specified by the file ' s owner in the Xib interface, fill in self, so that it can drag the line directly//1,xib the class of file ' owner ' specified in the interface. Purpose However, when you right-click on the interface, you can eject the line//2, to connect//3, the code loadnibnamed specifies which instance object the owner is, equivalent to the first parameter in addtarget nsarray *arrayxibobjects = [NS    Bundle Mainbundle] loadnibnamed:@ "Rowview" owner:self Options:nil];    UIView *rowview = arrayxibobjects[0];    The Y value of the newly added row depends on the y + height + 1 UIView *lastview = Self.view.subviews.lastObject of the last child control in the view;    CGFloat rowy = lastview.frame.origin.y + lastview.frame.size.height+1;    Rowview.backgroundcolor = [Uicolor Graycolor];    CGFloat winwidth = self.view.frame.size.width;    Rowview.frame = CGRectMake (Rowy,winwidth, krowhight);            Rowview.alpha = 0;    Assuming that the last sheet of the array is added, start from the beginning by adding if (_index >= _array_name.count) {_index = 0;      }//2, set label content UILabel *name = (UILabel *) [Rowview viewwithtag:1];  Name.text = _array_name[_index];    3, set headbtn content UIButton *btn = (UIButton *) [Rowview viewwithtag:2];    NSString *imgname = [NSString stringwithformat:@ "%d.png", _index];    UIImage *img = [UIImage imagenamed:imgname];    [Btn setimage:img Forstate:uicontrolstatenormal]; Add a Click event for button//[BTN addtarget:self Action: @selector (Headbtnclick:) forcontrolevents:uicontroleventtouchupinside        ];    4, set deletebtn content UIButton *del = (UIButton *) [Rowview Viewwithtag:3]; To delete the button join Click event [del addtarget:self action: @selector (Deletebtnclick:) forControlEvents:        UIControlEventTouchUpInside];    Prepare _index++ for the next join line; return Rowview;}        Create a line with code rowview-(UIView *) createrowviewbycoding{//Assuming that the last sheet of the array is added, start from the beginning by adding if (_index >= _array_name.count) {    _index = 0;    }//Join a row, real view,view in the left is the avatar, the right is the name UIView *rowview = [[UIView alloc]init];    The Y value of the newly added row depends on the y + height + 1 UIView *lastview = Self.view.subviews.lastObject of the last child control in the view; CgfloAt rowy = lastview.frame.origin.y + lastview.frame.size.height+1;    Rowview.backgroundcolor = [Uicolor Graycolor];    CGFloat winwidth = self.view.frame.size.width;    Rowview.frame = CGRectMake (Rowy,winwidth, krowhight);    Rowview.alpha = 0;    2, add label to view UILabel *name = [[UILabel alloc]init];    Name.frame = CGRectMake (0, 0, +, krowhight);    Name.backgroundcolor = [Uicolor Clearcolor];    Name.textalignment = Nstextalignmentcenter; Name.tag = 1;    Convenient back click on the Avatar button, get the brother tag that name//random index, take the name, take the picture with the//int Randindex = Arc4random_uniform (_array_name.count);    Name.text = _array_name[randindex];    Name.text = _array_name[_index];    [Rowview Addsubview:name]; 3, add avatar to view//UIImage *img = [UIImage imagenamed:@ "nana.jpg"];//uiimageview *head = [[Uiimageview ALLOC]INITW        ithimage:img];//head.frame = CGRectMake (0, 0,50, +);//[Rowview Addsubview:head];    3, add Avatar button to view UIButton *btn = [[UIButton alloc]init]; Btn.frame = CgrectmaKe (0, 0,65, krowhight);    NSString *imgname = [NSString stringwithformat:@ "%d.png", _index];    UIImage *img = [UIImage imagenamed:imgname];    [Btn setimage:img Forstate:uicontrolstatenormal];    Add a Click event to the button [BTN addtarget:self action: @selector (Headbtnclick:) forcontrolevents:uicontroleventtouchupinside];        [Rowview ADDSUBVIEW:BTN];    4, add Delete button to view UIButton *del = [[UIButton alloc]init];    Del.frame = CGRectMake (260, 0,65, krowhight);    [Del settitle:@ "Goodbye" forstate:uicontrolstatenormal]; To delete the button join Click event [del addtarget:self action: @selector (Deletebtnclick:) forControlEvents:    UIControlEventTouchUpInside];        [Rowview Addsubview:del];    Prepare _index++ for the next join line; return Rowview;}    Click Rowview inside the delete button-(void) Deletebtnclick: (UIButton *) sender{//Get rowview UIView *rowview = Sender.superview; [UIView animatewithduration:0.3 animations:^{///The following three steps are OC Standard Code, because OC does not agree to directly repair the object in the structure of the member of the property of the value, to pass the middle of the temporary structure of the body variable Cgrec  t frame = rowview.frame;      Frame.origin.x = 320;        Rowview.frame=frame;    Rowview.alpha = 0; } completion:^ (BOOL finished) {//Rowview in parent container index int rowview_index = [Self.view.subviews indexofobject:row        View];         Remove Rowview from its parent control, or Self.view [Rowview Removefromsuperview];                _trashitem.enabled = self.view.subviews.count!=1; Rowview behind these Rowview animations move up for (int i=rowview_index; i<self.view.subviews.count; i++) {//Rowview behind            These rowview animations move up UIView *rowviewsibling = self.view.subviews[i];                [UIView animatewithduration:0.3 animations:^{///The following three steps are OC Standard code, since OC does not agree to directly fix the value of the member of the struct attribute in the object, to pass the middle of the temporary structure of the body variable                CGRect frame = rowviewsibling.frame;                FRAME.ORIGIN.Y-= krowhight + 1;            Rowviewsibling.frame=frame;        }];    }    }];    }//Click on the Avatar button, pop-up alterview-(void) Headbtnclick: (UIButton *) sender{NSLog (@ "Click the Avatar button--%@", sender); UIView *rowview = Sender.superView    UILabel *name = (UILabel *) [Rowview viewwithtag:1];        NSLog (@ "The brother tag of clicked button is:%@", name);        Eject Alterview Uialertview *alert = [[Uialertview alloc]init]; [Alert show];}    Click Delete buttonitem-(ibaction) Removeclick: (Uibarbuttonitem *) Sender {_trashitem.enabled = NO;    Delete last line UIView *last = [Self.view.subviews lastobject];    Class CLS = [Uitoolbar class];    if ([last Iskindofclass:cls]) {return; }//animation effect [UIView animatewithduration:0.2 animations:^{///The following three steps are OC Standard Code, because OC does not agree to directly repair the value of the member of the struct attribute in the object, to be through the interim structure in the middle of the change        Volume CGRect frame = last.frame;        Frame.origin.x = 320;        Last.frame=frame;    Last.alpha = 0;        } completion:^ (BOOL finished) {//animation complete, remove [last Removefromsuperview] from parent control;    After deletion, let's delete barbuttionitem gray _trashitem.enabled = self.view.subviews.count! = 1;        }]; } @end


RowView.h

  rowview.h//  6_toolbar////  Created by Beyond on 14-7-24.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface rowview:uiview@property (weak, nonatomic) Iboutlet UIButton *headbtn; @property (weak, nonatomic) Iboutlet UILabel *namelabel;-(ibaction) Deletebtnclick: (UIButton *) sender;+ (Rowview *) Rowviewwithheadname: (NSString *) headname andlabelname: (NSString *) labelname AndRowY: (CGFloat) Rowy; @end


rowview.m

rowview.m//6_toolbar////Created by Beyond on 14-7-24.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "RowView.h" #define Krowhight 65@implementation rowview-(ID) initWithFrame: (CGRect) frame    {self = [super Initwithframe:frame]; if (self) {//initialization code} return self;}  /*//only override drawrect:if your perform custom drawing.//an empty implementation adversely affects performance during animation.-(void) DrawRect: (cgrect) rect{//Drawing code}*///The class method cannot be used directly to access member variables and must be passed through the object. Access to member variables//Parameters 1: Icon name for Avatar button , number 2: Name tag + (Rowview *) Rowviewwithheadname: (NSString *) headname andlabelname: (NSString *) labelname androwy: (CGFloat) rowy{//Mainbundel loading xib, extension not written. xib Nsarray *arrayxibobjects = [[NSBundle mainbundle] loadnibnamed:@ "Rowview" owner:        Nil Options:nil];    Rowview *rowview = arrayxibobjects[0];    1, set the properties of Rowview Rowview.backgroundcolor = [Uicolor Graycolor]; First on the outside of the screen, so x is the Rowview.frame = CGRectMake (Rowy,(Krowhight);        Rowview.alpha = 0; 2, set the label content//tag to traverse, inefficient, not recommended, preferably rowview.xib wire to RowView.h file, use member variable//UILabel *namelabel = (UILabel *) [Rowview vie        WWITHTAG:1];        RowView.nameLabel.text = LabelName; 3, set HEADBTN content//tag to traverse, inefficient, not recommended, preferably rowview.xib wire to RowView.h file, using member variable//UIButton *HEADBTN = (UIButton *) [Rowview V        Iewwithtag:2];    UIImage *img = [UIImage imagenamed:headname];    [Rowview.headbtn setimage:img Forstate:uicontrolstatenormal]; return Rowview;} The Delete button in Rowview is clicked-(ibaction) Deletebtnclick: (UIButton *) Sender {//get rowview UIView *rowview = Sender.superv        Iew; [UIView animatewithduration:0.3 animations:^{///The following three steps are OC Standard Code, because OC does not agree to directly repair the object in the structure of the member of the property of the value, to pass the middle of the temporary structure of the body variable CGRect        frame = Rowview.frame;        Frame.origin.x = 320;        Rowview.frame=frame;    Rowview.alpha = 0;        } completion:^ (BOOL finished) {//nslog (@ "Rowview.superview is%@", Rowview.superview); Get the UIView of the controller first UivieW *control_view = Rowview.superview;        Rowview index in the parent container int rowview_index = [Control_view.subviews Indexofobject:rowview];        Remove Rowview from its parent control, or Self.view [Rowview Removefromsuperview]; Rowview behind these Rowview animations move on for (int i=rowview_index; i<control_view.subviews.count; i++) {//Rowview            Behind these rowview animations move up UIView *rowviewsibling = control_view.subviews[i];                [UIView animatewithduration:0.3 animations:^{///The following three steps are OC Standard code, since OC does not agree to directly fix the value of the member of the struct attribute in the object, to pass the middle of the temporary structure of the body variable                CGRect frame = rowviewsibling.frame;                FRAME.ORIGIN.Y-= krowhight + 1;            Rowviewsibling.frame=frame;        }]; }    }];} @end


Rowview.xib



















Ios_6_toolbar+xib+ Dream of Red mansions

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.