IOS添加控件
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;
}