首页 / IOS / ios-利用xib重新写 应用管理
ios-利用xib重新写 应用管理
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ios-利用xib重新写 应用管理,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3830字,纯文字阅读大概需要6分钟。
内容图文
![ios-利用xib重新写 应用管理](/upload/InfoBanner/zyjiaocheng/1128/1f6b819825e94dac8d7fa5c681a3903a.jpg)
// // app.h // 应用管理 // // Created by YaguangZhu on 15/7/31. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <Foundation/Foundation.h> @interface app : NSObject @property (nonatomic,copy) NSString *miaoshu; @property (nonatomic,copy) NSString *icon; - (app *)initWithDict:(NSDictionary *)dict; + (app *)appwithDict:(NSDictionary *)dict; @end
// // app.m // 应用管理 // // Created by YaguangZhu on 15/7/31. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import " app.h " @implementation app -(app *)initWithDict:(NSDictionary *)dict { if (self = [super init]) { self.miaoshu = dict[@"miaoshu"]; self.icon = dict[@"icon"]; } return self; } + (app *)appwithDict:(NSDictionary *)dict { return [[self alloc] initWithDict:dict]; } @end
// // CZAppView.h // 应用管理 // // Created by YaguangZhu on 15/8/1. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <UIKit/UIKit.h> @class app; @interface CZAppView : UIView @property (nonatomic,strong) app *model; @end
// // CZAppView.m // 应用管理 // // Created by YaguangZhu on 15/8/1. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import " CZAppView.h " #import " app.h " @interface CZAppView () @property (weak, nonatomic) IBOutlet UIImageView *imgViewIcon; @property (weak, nonatomic) IBOutlet UILabel *lblName; @property (weak, nonatomic) IBOutlet UIButton *btnDownload; @end@implementation CZAppView /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during 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 // 应用管理 // // Created by YaguangZhu on 15/7/31. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import " ViewController.h " #import " app.h " #import " CZAppView.h " @interface ViewController () @property (nonatomic,strong) NSArray *apps; @end@implementation ViewController - (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 *dict in array) { app *model = [app appwithDict:dict]; // model.miaoshu = dict[@"miaoshu"]; // model.icon = dict[@"icon"]; [arrayModels addObject:model]; } _apps =arrayModels; } return _apps; } - (void)viewDidLoad { [super viewDidLoad]; int colums =3; CGFloat viewWidth = self.view.frame.size.width; CGFloat appW = 75; CGFloat appH = 90; CGFloat marginTop = 30; CGFloat maginX = (viewWidth - colums*appW)/ (colums+1); CGFloat maginY = maginX; for (int i=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]; int colIdx = i % colums; int rowIdx = 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]; // 用tag来给控件赋值 // UIImageView *imgViewIcon = (UIImageView *)[appview viewWithTag:1000]; // imgViewIcon.image = [UIImage imageNamed:appModel.icon]; //// UILabel *lblName = (UILabel*)[appview viewWithTag:2000]; // lblName.text = appModel.miaoshu; //用自己创建一个类 然后拖拉控件来赋值 // appview.imgViewIcon.image = [UIImage imageNamed:appModel.icon]; // appview.lblName.text = appModel.miaoshu; //以上不这样写说为了安全 和封装性好 appview.model = appModel; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.} @end
原文:http://www.cnblogs.com/zhuyaguang/p/4694138.html
内容总结
以上是互联网集市为您收集整理的ios-利用xib重新写 应用管理全部内容,希望文章能够帮你解决ios-利用xib重新写 应用管理所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。