51.小项目:应用管理 Part1

---------- ViewController.m ----------
#import "ViewController.h"
#import "CZApp.h"
#import "CZAppCell.h"
@interfaceViewController ()<CZAppCellDelegate>
@property (nonatomic, strong) NSArray *apps;
@end
@implementation ViewController
- (BOOL)prefersStatusBarHidden
{
returnYES;
}
- (NSArray *)apps
{
if (_apps == nil)
{
NSArray *dictArray = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"apps_full.plist"ofType:nil]];
NSMutableArray *appArray = [NSMutableArrayarray];
for (NSDictionary *dict in dictArray)
{
CZApp *app = [CZApp appWithDict:dict];
[appArray addObject:app];
}
_apps = appArray;
}
return _apps;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
returnself.apps.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CZAppCell *cell = [tableView dequeueReusableCellWithIdentifier:@"app"];
cell.delegate = self;
cell.app = self.apps[indexPath.row];
return cell;
}
- (void)appCellDidClickedDownloadBtn:(CZAppCell *)cell
{
CZApp *app = cell.app;
UILabel *label = [[UILabel alloc] init];
label.text = [NSString stringWithFormat:@"成功下载%@", app.name];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColorblackColor];
label.frame = CGRectMake(0, 0, 150, 25);
label.center = CGPointMake(160, 240);
label.alpha = 0.0;
label.layer.cornerRadius = 5;
label.clipsToBounds = YES;
[self.view addSubview:label];
[UIViewanimateWithDuration:0.5animations:^{
label.alpha = 0.5;
} completion:^(BOOL finished) {
[UIViewanimateWithDuration:0.5delay:0.5options:UIViewAnimationOptionCurveLinearanimations:^{
label.alpha = 0.0;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}
@end
浙公网安备 33010602011771号