一个人建网站,做文库网站怎么赚钱吗,wordpress 网站死机,创可贴在线设计网站之前写过ios动态创建控件及添加事件#xff0c;纯手工代码写控件#xff0c;虽然比较灵活#xff0c;但是就是代码量比较多。这次我们通过xib来创建app下载列表项 AppView.xib。一个imageview,一个label,一个button构成
1.创建AppView.xib 2.再创建xib对应的mode#xff0…之前写过ios动态创建控件及添加事件纯手工代码写控件虽然比较灵活但是就是代码量比较多。这次我们通过xib来创建app下载列表项 AppView.xib。一个imageview,一个label,一个button构成
1.创建AppView.xib 2.再创建xib对应的modeAppView.h 继承至UIView 实现效果如下 3.xib页面设计好了之后将控件拖入AppView.h
//
// AppView.h
// iosstudy2024
//
// Created by figo on 2025/2/10.
//#import UIKit/UIKit.hNS_ASSUME_NONNULL_BEGINinterface AppView : UIView
property (weak, nonatomic) IBOutlet UIImageView *iconImg;
property (weak, nonatomic) IBOutlet UILabel *appName;
property (weak, nonatomic) IBOutlet UIButton *btnDownload;endNS_ASSUME_NONNULL_END4.列表配置文件icons.plist
?xml version1.0 encodingUTF-8?
!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd
plist version1.0
arraydictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dictdictkeyname/keystring文心一言/stringkeyicon/keystringstar/string/dictdictkeyname/keystring豆包/stringkeyicon/keystringgrape/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringwatermenon/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dictdictkeyname/keystringdeepseek/stringkeyicon/keystringdiamond/string/dict
/array
/plist5.添加控制器AppDownloadViewController.m
//
// AppDownloadViewController.m
// iosstudy2024
//
// Created by figo on 2025/2/10.
//#import AppDownloadViewController.h
#import AppView.h
interface AppDownloadViewController ()
property (nonatomic,strong) NSArray *iconArray;endimplementation AppDownloadViewController
- (NSArray *)iconArray{if(_iconArraynil){NSString *path[[NSBundle mainBundle]pathForResource:icons.plist ofType:nil];_iconArray[NSArray arrayWithContentsOfFile:path];}return _iconArray;
}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.//[self initApp];[self initAppUseXib];}-(void) initApp{// Do any additional setup after loading the view from its nib.NSUInteger countself.iconArray.count;NSBundle *boundle[NSBundle mainBundle];for(int a0;acount;a){//添加外边框UIView *uiView[UIView new];//new的方式uiView.backgroundColor[UIColor blueColor];CGFloat x50(a%3)*(7510);CGFloat y50(a/3)*(10010);uiView.frameCGRectMake(x, y, 75, 100);//x,y,w,h//外边框内部添加图片UIImageView *uiImageView[UIImageView new];uiImageView.backgroundColor[UIColor greenColor];CGFloat iconW45;CGFloat iconH45;CGFloat x1(uiView.frame.size.width-iconW)*0.5;//相对坐标CGFloat y10;//相对坐标uiImageView.frameCGRectMake(x1, y1, iconW, iconH);//x,y,w,hNSDictionary *dictionaryself.iconArray[a];// NSString *imgPath [NSString stringWithFormat:%/%.jpg, [[NSBundle mainBundle] resourcePath], dictionary[icon]];NSString *imgPath[[NSBundle mainBundle]pathForResource:dictionary[icon] ofType:.jpeg];//照片拖入Assets.xcassets文件夹会找不到资源注意需要项目下新建group命名为Supporting Files再项目外新建文件夹比如icons然后将图片放入icons,再将icons文件夹拖入Supporting Files才能找到否则返回nilUIImage *uiImage[UIImage imageWithContentsOfFile:imgPath];//imageWithContentsOfFile不会缓存每次都重新加载图片
// UIImage *uiImage[UIImage imageNamed:dictionary[icon]];//imageNamed会缓存,照片拖入Assets.xcassets文件夹即可图片非常多会占用很多内存uiImageView.imageuiImage;[uiView addSubview:uiImageView];//外边框内部标题UILabel *uiLabel[UILabel new];uiLabel.backgroundColor[UIColor yellowColor];CGFloat labelWuiView.frame.size.width;CGFloat labelH20;CGFloat x20;//相对坐标CGFloat y2uiImageView.frame.size.height5;//相对坐标uiLabel.frameCGRectMake(x2, y2, labelW, labelH);//x,y,w,huiLabel.textdictionary[name];[uiLabel setTextAlignment:NSTextAlignmentCenter];[uiView addSubview:uiLabel];//外边框内部添加按钮UIButton *uiButton[UIButton new];uiButton.backgroundColor[UIColor redColor];CGFloat buttonW55;CGFloat buttonH20;CGFloat x3(75-55)*0.5;//相对坐标CGFloat y3uiImageView.frame.size.heightuiLabel.frame.size.height55;//相对坐标uiButton.frameCGRectMake(x3, y3, buttonW, buttonH);//x,y,w,h[uiButton setTitle:下载 forState:UIControlStateNormal];[uiButton addTarget:self action:selector(onclick:) forControlEvents:UIControlEventTouchUpInside];uiButton.taga;[uiView addSubview:uiButton];[self.view addSubview:uiView];}
}-(void) initAppUseXib{// Do any additional setup after loading the view from its nib.NSUInteger countself.iconArray.count;NSBundle *boundle[NSBundle mainBundle];for(int a0;acount;a){//添加外边框//通过xib文件获取的方式AppView *uiView[[boundle loadNibNamed:AppView owner:nil options:nil]lastObject];uiView.backgroundColor[UIColor purpleColor];CGFloat x50(a%3)*(7510);CGFloat y50(a/3)*(10010);uiView.frameCGRectMake(x, y, 75, 100);//x,y,w,h//外边框内部添加图片uiView.iconImg.backgroundColor[UIColor greenColor];NSDictionary *dictionaryself.iconArray[a];NSString *imgPath[[NSBundle mainBundle]pathForResource:dictionary[icon] ofType:.png];//照片拖入Assets.xcassets文件夹会找不到资源注意需要项目下新建group命名为Supporting Files再项目外新建文件夹比如icons然后将图片放入icons,再将icons文件夹拖入Supporting Files才能找到否则返回nilUIImage *uiImage[UIImage imageWithContentsOfFile:imgPath];//imageWithContentsOfFile不会缓存每次都重新加载图片
// UIImage *uiImage[UIImage imageNamed:dictionary[icon]];//imageNamed会缓存,照片拖入Assets.xcassets文件夹即可图片非常多会占用很多内存uiView.iconImg.imageuiImage;//外边框内部标题uiView.appName.backgroundColor[UIColor yellowColor];uiView.appName.textdictionary[name];[uiView.btnDownload addTarget:self action:selector(onclick:) forControlEvents:UIControlEventTouchUpInside];uiView.btnDownload.taga;[self.view addSubview:uiView];}
}-(void)onclick:(UIButton *)uiButton{NSLog(%d点击下载,uiButton.tag);
}
end6.SceneDelegate.m修改当前controller为AppDownloadViewController
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {AppDownloadViewController * viewController [[AppDownloadViewController alloc]init];self.window.rootViewControllerviewController;
}
文章转载自: http://www.morning.mnygn.cn.gov.cn.mnygn.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.pctql.cn.gov.cn.pctql.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.rlbc.cn.gov.cn.rlbc.cn http://www.morning.tnkwj.cn.gov.cn.tnkwj.cn http://www.morning.nkyc.cn.gov.cn.nkyc.cn http://www.morning.brlcj.cn.gov.cn.brlcj.cn http://www.morning.mknxd.cn.gov.cn.mknxd.cn http://www.morning.cjqqj.cn.gov.cn.cjqqj.cn http://www.morning.fplqh.cn.gov.cn.fplqh.cn http://www.morning.twhgn.cn.gov.cn.twhgn.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.xhgxd.cn.gov.cn.xhgxd.cn http://www.morning.xnlj.cn.gov.cn.xnlj.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.lxfdh.cn.gov.cn.lxfdh.cn http://www.morning.bpcf.cn.gov.cn.bpcf.cn http://www.morning.jyyw.cn.gov.cn.jyyw.cn http://www.morning.lgtcg.cn.gov.cn.lgtcg.cn http://www.morning.pfgln.cn.gov.cn.pfgln.cn http://www.morning.rdng.cn.gov.cn.rdng.cn http://www.morning.nhgfz.cn.gov.cn.nhgfz.cn http://www.morning.zcnfm.cn.gov.cn.zcnfm.cn http://www.morning.dwrbn.cn.gov.cn.dwrbn.cn http://www.morning.nlysd.cn.gov.cn.nlysd.cn http://www.morning.wchsx.cn.gov.cn.wchsx.cn http://www.morning.ywpcs.cn.gov.cn.ywpcs.cn http://www.morning.pqnps.cn.gov.cn.pqnps.cn http://www.morning.smdkk.cn.gov.cn.smdkk.cn http://www.morning.cpmfp.cn.gov.cn.cpmfp.cn http://www.morning.rnfn.cn.gov.cn.rnfn.cn http://www.morning.yqkmd.cn.gov.cn.yqkmd.cn http://www.morning.zntf.cn.gov.cn.zntf.cn http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn http://www.morning.lxyyp.cn.gov.cn.lxyyp.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.lzqxb.cn.gov.cn.lzqxb.cn http://www.morning.ycnqk.cn.gov.cn.ycnqk.cn http://www.morning.fpjw.cn.gov.cn.fpjw.cn http://www.morning.qtryb.cn.gov.cn.qtryb.cn http://www.morning.prhfc.cn.gov.cn.prhfc.cn http://www.morning.kcxtz.cn.gov.cn.kcxtz.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.xptkl.cn.gov.cn.xptkl.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.xmwdt.cn.gov.cn.xmwdt.cn http://www.morning.gygfx.cn.gov.cn.gygfx.cn http://www.morning.wplbs.cn.gov.cn.wplbs.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.rqlzz.cn.gov.cn.rqlzz.cn http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn http://www.morning.prfrb.cn.gov.cn.prfrb.cn http://www.morning.qshxh.cn.gov.cn.qshxh.cn http://www.morning.yzfrh.cn.gov.cn.yzfrh.cn http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.amlutsp.cn.gov.cn.amlutsp.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.hfxks.cn.gov.cn.hfxks.cn http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn http://www.morning.lkxzb.cn.gov.cn.lkxzb.cn http://www.morning.wypyl.cn.gov.cn.wypyl.cn http://www.morning.dwfzm.cn.gov.cn.dwfzm.cn http://www.morning.rsfp.cn.gov.cn.rsfp.cn http://www.morning.mldrd.cn.gov.cn.mldrd.cn http://www.morning.njntp.cn.gov.cn.njntp.cn http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn http://www.morning.fchkc.cn.gov.cn.fchkc.cn http://www.morning.lxjxl.cn.gov.cn.lxjxl.cn http://www.morning.dpqwq.cn.gov.cn.dpqwq.cn http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn http://www.morning.hjwzpt.com.gov.cn.hjwzpt.com