ios-利用xib重新寫 應用管理

來源:互聯網
上載者:User

標籤:

////  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

 

ios-利用xib重新寫 應用管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.