25.小项目:应用市场 版本8.0

------------- CZapp.h -------------

#import <Foundation/Foundation.h>

@interface CZApp : NSObject

@property (nonatomic,copy) NSString *name;

@property (nonatomic,copy) NSString *icon;

- (instancetype) initWithDict:(NSDictionary *) dict;

+ (instancetype) appWithDict:(NSDictionary *) dict;

+ (NSArray *) apps;

@end

------------- CZapp.m -------------

#import "CZApp.h"

@implementation CZApp

- (instancetype)initWithDict:(NSDictionary *)dict

{

if (self = [super init])

{

self.name = dict[@"name"];

self.icon = dict[@"icon"];

}

return self;

}

+ (instancetype)appWithDict:(NSDictionary *)dict

{

return [[self alloc] initWithDict:dict];

}

+ (NSArray *) apps

{

NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"plist"];

NSArray *array = [NSArray arrayWithContentsOfFile:path];

NSMutableArray *arrayM = [NSMutableArray array];

for (NSDictionary *dict in array)

{

CZApp *app = [CZApp appWithDict:dict];

[arrayM addObject:app];

}

return arrayM;

}

@end

------------- CZappView.h -------------

#import <UIKit/UIKit.h>

#import "CZApp.h"

@interface CZAppView : UIView

@property (nonatomic,strong) CZApp *app;

@end

------------- CZappView.m -------------

#import "CZAppView.h"

@interface CZAppView ()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

- (IBAction)download:(UIButton *)sender;

@end

@implementation CZAppView

- (void)setApp:(CZApp *)app

{

_app = app;

self.iconView.image = [UIImage imageNamed:app.icon];

self.nameLabel.text = app.name;

}

- (IBAction)download:(UIButton *)sender

{

sender.enabled = NO;

self.superview.userInteractionEnabled = NO;

UILabel *tipLable = [[UILabel alloc] init];

tipLable.backgroundColor = [UIColor grayColor];

[self.superview addSubview:tipLable];

tipLable.center = self.superview.center;

tipLable.bounds = CGRectMake(0,0, 200, 40);

tipLable.text = [NSString stringWithFormat:@"%@下载成功!",self.app.name];

tipLable.textAlignment = NSTextAlignmentCenter;

tipLable.layer.cornerRadius = 10;

tipLable.layer.masksToBounds = YES;

tipLable.alpha = 0.0;

[UIView animateWithDuration:1 animations:^{tipLable.alpha = 0.8;} completion:^(BOOL finished)

{

[UIView animateWithDuration:1 delay:1 options: UIViewAnimationOptionCurveLinear animations:^{

tipLable.alpha = 0.0;} completion:^(BOOL finished)

{

[tipLable removeFromSuperview];

self.superview.userInteractionEnabled = YES;

}];

}];

}

@end

------------- ViewController.m -------------

#import "ViewController.h"

#import "CZApp.h"

#import "CZAppView.h"

@interface ViewController ()

@property (nonatomic,strong) NSArray *apps;

@end

@implementation ViewController

- (NSArray *)apps

{

if(_apps == nil)

{

_apps = [CZApp apps];

}

return _apps;

}

- (void)viewDidLoad

{

[super viewDidLoad];

CGFloat appW = 100;

CGFloat appH = 100;

int numOfCol = 3;

CGFloat marginX = (self.view.frame.size.width - appW * numOfCol) / (numOfCol + 1);

CGFloat marginY = 20;

for (int index = 0; index < self.apps.count; index++)

{

CZAppView *appView  = [[[NSBundle mainBundle] loadNibNamed:@"CZAppView" owner:nil options:nil] lastObject];

int col = index % numOfCol;

CGFloat appX = marginX + (appW + marginX) * col;

int row = index / numOfCol;

CGFloat appY = 20 + marginY + (appH + marginY) * row;

appView.frame = CGRectMake(appX, appY,appW,appH);

[self.view addSubview:appView];

CZApp *app = self.apps[index];

appView.app = app;

}

}

@end

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

时间: 2024-10-14 04:49:57

25.小项目:应用市场 版本8.0的相关文章

32.小项目:喜马拉雅 版本3.0

更新说明:图片轮播器拖拽图片时暂停轮播. ------------- ViewController.m ------------- #import "ViewController.h" #define IMAGE_COUNT 5 @interface ViewController () <UIScrollViewDelegate> @property (weak, nonatomic) IBOutlet UIScrollView *scrView; @property (n

31.小项目:喜马拉雅 版本2.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 更新说明:添加图片轮播器 --

30.小项目:喜马拉雅 版本1.0

------------- ViewController.m ------------- #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIScrollView *scrView; @property (nonatomic,strong) NSArray *arrs; @end @implementation ViewController - (N

24.小项目:应用市场 版本7.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); ------------- CZapp.h ------------- #import <Foundation/Foundation.h> @interface CZApp : NSObject @property (nonatomic,copy) NSSt

22.小项目:应用市场 版本5.0

------------- CZapp.h ------------- #import <Foundation/Foundation.h> @interface CZApp : NSObject @property (nonatomic,copy) NSString *name; @property (nonatomic,copy) NSString *icon; - (instancetype) initWithDict:(NSDictionary *) dict; + (instancet

26.小项目:应用市场 版本9.0

------------- CZapp.h ------------- #import <Foundation/Foundation.h> @interface CZApp : NSObject @property (nonatomic,copy) NSString *name; @property (nonatomic,copy) NSString *icon; - (instancetype) initWithDict:(NSDictionary *) dict; + (instancet

23.小项目:应用市场 版本6.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); ------------- C

21.小项目:应用市场 版本4.0

------------- CZapp.h ------------- #import <Foundation/Foundation.h> @interface CZApp : NSObject @property (nonatomic,copy) NSString *name; @property (nonatomic,copy) NSString *icon; @end ------------- CZapp.m ------------- #import "CZApp.h&qu

20.小项目:应用市场 版本3.0

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); ------------- ViewController.m ------------- #import "ViewController.h" @interface ViewController () @property (nonatomic,str