码迷,mamicode.com
首页 > 移动开发 > 详细

IOS添加控件

时间:2015-10-18 11:19:21      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

        YJQApp *appInfo =self.apps[i];
        
        
        //.添加图片
        UIImageView * iconView = [[UIImageView alloc]init];
        CGFloat iconW= 22;
        CGFloat iconH =33;
        CGFloat iconX =(appW-iconW)*0.5;
        CGFloat iconY=0;
        iconView.frame=CGRectMake(iconX, iconY, iconW, iconH);
        
        iconView.image = [UIImage imageNamed:appInfo.icon];
        [appView addSubview:iconView];
        
        //.添加文字
        UILabel * nameLabel =[[UILabel alloc] init];
        CGFloat nameW = appW;
        CGFloat nameH = 20;
        CGFloat nameX = 0;
        CGFloat nameY = iconY+iconH;
        nameLabel.frame =CGRectMake(nameX, nameY, nameW, nameH);
        
        nameLabel.text=appInfo.icon;
        
        nameLabel.font =[UIFont systemFontOfSize:13];
        
        nameLabel.textAlignment = NSTextAlignmentCenter;
        
        [appView addSubview:nameLabel];
        
        //. 添加按钮
        UIButton * downloadBtn =[[UIButton alloc]init];
        CGFloat downloadX=12;
        CGFloat downloadY=nameY+nameH;
        CGFloat downloadW=appW-2*downloadX;
        CGFloat downloadH=20;
        downloadBtn.frame = CGRectMake(downloadX, downloadY, downloadW, downloadH);
        
        //设置默认背景
        UIImage * normalImage = [UIImage imageNamed:@"cc"];
        [downloadBtn setBackgroundImage: normalImage forState:UIControlStateNormal];
        
        
        //设置高亮背景
        UIImage * highImage =[UIImage imageNamed:@"cc"];
        [downloadBtn setBackgroundImage:highImage forState:UIControlStateHighlighted];
        
        //设置文字
        [downloadBtn setTitle:@"cc" forState:UIControlStateNormal];
        
        //设置文章字体
        downloadBtn.titleLabel.font=[UIFont systemFontOfSize:13];
        
        [appView addSubview:downloadBtn];



- (NSArray *)apps{

    if(_apps==nil){

        //获取plist文件 全路径

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

        NSArray * dicArray =[NSArray arrayWithContentsOfFile:path];

        NSMutableArray * appAarry =[NSMutableArray array];

       for(NSDictionary * dic  in dicArray){
            YJQApp * app = [YJQApp appWithDict:dic];

             [appAarry addObject:app];


        }


        _apps = appAarry;


    }


    return _apps;


}

 

 

IOS添加控件

标签:

原文地址:http://www.cnblogs.com/yangjingqi/p/4889097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!