• ios-应用管理


    //
    //  ViewController.m
    //  应用管理
    //
    //  Created by YaguangZhu on 15/7/31.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "ViewController.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];
            _apps =array;
            
        }
        
        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
        {
            
            NSDictionary *appDict = self.apps[i];
        UIView *appview = [[UIView alloc] init];
       // appview.backgroundColor = [UIColor redColor];
            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];
            // 增加子控件
            UIImageView *imgViewIcon = [[UIImageView alloc]init];
           // imgViewIcon.backgroundColor = [UIColor blueColor];
            CGFloat iconW = 45;
            CGFloat iconH =45;
            CGFloat iconX = (appview.frame.size.width- iconW) *0.5;
            CGFloat iconY = 0;
            imgViewIcon.frame = CGRectMake(iconX, iconY, iconW, iconH);
            
            [appview addSubview:imgViewIcon];
            imgViewIcon.image = [UIImage imageNamed:appDict[@"icon"]];
            
            
            
            
            
            
            UILabel *lblName = [[UILabel alloc] init];
            //lblName.backgroundColor = [UIColor yellowColor];
            CGFloat nameW = appview.frame.size.width;
            CGFloat nameH = 20;
            CGFloat nameY= iconH;
            CGFloat nameX = 0;
            lblName.frame = CGRectMake(nameX, nameY, nameW, nameH);
            [appview addSubview:lblName];
            
            UIButton *btnDowload = [[UIButton alloc] init];
            btnDowload.backgroundColor = [UIColor blackColor];
            lblName.text = appDict[@"miaoshu"];
            lblName.font = [UIFont systemFontOfSize:14];
            lblName.textAlignment = NSTextAlignmentCenter;
            
            
            
            
            CGFloat btnW =iconW;
            CGFloat btnH = 20;
            CGFloat btnX = iconX;
            //CGFloat btnY = nameY + nameH;
            CGFloat btnY = CGRectGetMaxY(lblName.frame);
            btnDowload.frame = CGRectMake(btnX, btnY, btnW, btnH);
            [appview addSubview:btnDowload];
            [btnDowload setTitle:@"xia zai" forState:UIControlStateNormal];
            [btnDowload setTitle:@"finsh" forState:UIControlStateHighlighted];
            [btnDowload setBackgroundImage:[UIImage imageNamed:@"12"] forState:UIControlStateNormal];
            [btnDowload setBackgroundImage:[UIImage imageNamed:@"10"] forState:UIControlStateHighlighted];
            btnDowload.titleLabel.font = [UIFont systemFontOfSize:14];
            
            //按钮的单击事件
            [btnDowload addTarget:self action:@selector(btnDownClick) forControlEvents:UIControlEventTouchUpInside];
            
        }
            
    }
    - (void)btnDownClick
    {
        NSLog(@"ssss");
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    .NET 动态脚本语言
    webParts与Web部件
    比较JqGrid与XtraGrid
    XtraGrid滚轮翻页
    Python------继承
    Python 私有化类的属性
    Python print 输出不换行,只有空格
    Python--函数参数类型
    手推FP-growth (频繁模式增长)算法------挖掘频繁项集
    Python 返回多个值+Lambda的使用
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4692179.html
Copyright © 2020-2023  润新知