ios-using Xib to re-write application management

Source: Internet
Author: User

////App.h//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<Foundation/Foundation.h>@interfaceApp:nsobject@property (nonatomic,copy) NSString*Miaoshu, @property (nonatomic,copy) NSString*icon;-(APP *) Initwithdict: (Nsdictionary *) dict;+ (APP *) Appwithdict: (Nsdictionary *) dict;@end
////app.m//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "App.h"@implementationapp-(APP *) Initwithdict: (Nsdictionary *) dict{if(self =[Super Init]) {Self.miaoshu= dict[@"Miaoshu"]; Self.icon= dict[@"icon"]; }    returnSelf ;}+ (APP *) Appwithdict: (Nsdictionary *) dict{return[Self alloc] initwithdict:dict];}@end

// //   CZAppView.h/ /   Application Management ////  Created by Yaguangzhu on 15/ 8/1. //   Copyright (c) 2015 Yaguangzhu. All rights reserved. // #import <UIKit/UIKit.h>@class  app; @interface  *model; @end
////czappview.m//Application Management////Created by Yaguangzhu on 15/8/1.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "CZAppView.h"#import "App.h"@interfaceCzappview () @property (weak, nonatomic) Iboutlet Uiimageview*Imgviewicon, @property (weak, nonatomic) Iboutlet UILabel*Lblname, @property (weak, nonatomic) Iboutlet UIButton*Btndownload;@end@implementationCzappview/*//Only override drawrect:if your perform custom drawing.//an empty implementation adversely affects performance Duri ng animation.-(void) DrawRect: (cgrect) Rect {//Drawing code}*/- (void) Setmodel: (APP *) model{_model=model; Self.imgViewIcon.image=[UIImage ImageNamed:model.icon]; Self.lblName.text=Model.miaoshu;}@end
////VIEWCONTROLLER.M//Application Management////Created by Yaguangzhu on 15/7/31.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "App.h"#import "CZAppView.h"@interfaceViewcontroller () @property (nonatomic,strong) Nsarray*apps;@end@implementationViewcontroller-(Nsarray *) apps{if(_apps = =Nil) {NSString*path = [[NSBundle mainbundle] Pathforresource:@"app.plist"Oftype:nil]; Nsarray*array =[Nsarray Arraywithcontentsoffile:path]; Nsmutablearray*arraymodels =[Nsmutablearray array];  for(Nsdictionary *dictinchArray) {App*model =[app Appwithdict:dict]; //Model.miaoshu = dict[@ "Miaoshu"]; //Model.icon = dict[@ "icon"];[Arraymodels Addobject:model]; } _apps=Arraymodels; }        return_apps; }- (void) viewdidload {[Super viewdidload]; intColums =3; CGFloat viewwidth=Self.view.frame.size.width; CGFloat APPW= the; CGFloat APPH= -; CGFloat margintop= -; CGFloat Maginx= (VIEWWIDTH-COLUMS*APPW)/(colums+1); CGFloat Maginy=Maginx;  for(intI=0; i<self.apps.count;i++)//9 = Self.apps.count{app*appmodel =Self.apps[i]; NSBundle*rootboundle =[NSBundle Mainbundle]; Czappview*appview = [[Rootboundle loadnibnamed:@"Czappview"Owner:nil Options:nil] lastobject]; intColidx = i%colums; intRowidx = I/colums; CGFloat AppX= maginx+ Colidx * (APPW +Maginx); CGFloat Appy= MarginTop +rowidx * (APPH +maginy); Appview.frame=CGRectMake (AppX, Appy, APPW, APPH);       [Self.view Addsubview:appview]; //Assigning a value to a control with tag//Uiimageview *imgviewicon = (Uiimageview *) [Appview viewwithtag:1000];//imgviewicon.image = [UIImage ImageNamed:appModel.icon];//        //UILabel *lblname = (uilabel*) [Appview viewwithtag:2000];//lblname.text = Appmodel.miaoshu; //create a class with yourself and drag a control to assign a value//appview.imgViewIcon.image = [UIImage ImageNamed:appModel.icon];//appview.lblName.text = Appmodel.miaoshu; //The above does not say for the sake of safety and encapsulation goodAppview.model =Appmodel; }        }- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end

ios-using Xib to re-write application management

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.