当前位置: 首页 > news >正文

网站可以制作iosaso优化{ }贴吧

网站可以制作ios,aso优化{ }贴吧,wifi扩展器做网站,装修公司谁做网站之前写过ios动态创建控件及添加事件,纯手工代码写控件,虽然比较灵活,但是就是代码量比较多。这次我们通过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对应的mode,AppView.h 继承至UIView

实现效果如下:

3.xib页面设计好了之后,将控件拖入AppView.h

//
//  AppView.h
//  iosstudy2024
//
//  Created by figo on 2025/2/10.
//#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@interface AppView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *iconImg;
@property (weak, nonatomic) IBOutlet UILabel *appName;
@property (weak, nonatomic) IBOutlet UIButton *btnDownload;@endNS_ASSUME_NONNULL_END

4.列表配置文件icons.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict><dict><key>name</key><string>文心一言</string><key>icon</key><string>star</string></dict><dict><key>name</key><string>豆包</string><key>icon</key><string>grape</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>watermenon</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict><dict><key>name</key><string>deepseek</string><key>icon</key><string>diamond</string></dict>
</array>
</plist>

5.添加控制器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;@end@implementation AppDownloadViewController
- (NSArray *)iconArray{if(_iconArray==nil){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 count=self.iconArray.count;NSBundle *boundle=[NSBundle mainBundle];for(int a=0;a<count;a++){//添加外边框UIView *uiView=[UIView new];//new的方式uiView.backgroundColor=[UIColor blueColor];CGFloat x=50+(a%3)*(75+10);CGFloat y=50+(a/3)*(100+10);uiView.frame=CGRectMake(x, y, 75, 100);//x,y,w,h//外边框内部添加图片UIImageView *uiImageView=[UIImageView new];uiImageView.backgroundColor=[UIColor greenColor];CGFloat iconW=45;CGFloat iconH=45;CGFloat x1=(uiView.frame.size.width-iconW)*0.5;//相对坐标CGFloat y1=0;//相对坐标uiImageView.frame=CGRectMake(x1, y1, iconW, iconH);//x,y,w,hNSDictionary *dictionary=self.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.image=uiImage;[uiView addSubview:uiImageView];//外边框内部标题UILabel *uiLabel=[UILabel new];uiLabel.backgroundColor=[UIColor yellowColor];CGFloat labelW=uiView.frame.size.width;CGFloat labelH=20;CGFloat x2=0;//相对坐标CGFloat y2=uiImageView.frame.size.height+5;//相对坐标uiLabel.frame=CGRectMake(x2, y2, labelW, labelH);//x,y,w,huiLabel.text=dictionary[@"name"];[uiLabel setTextAlignment:NSTextAlignmentCenter];[uiView addSubview:uiLabel];//外边框内部添加按钮UIButton *uiButton=[UIButton new];uiButton.backgroundColor=[UIColor redColor];CGFloat buttonW=55;CGFloat buttonH=20;CGFloat x3=(75-55)*0.5;//相对坐标CGFloat y3=uiImageView.frame.size.height+uiLabel.frame.size.height+5+5;//相对坐标uiButton.frame=CGRectMake(x3, y3, buttonW, buttonH);//x,y,w,h[uiButton setTitle:@"下载" forState:UIControlStateNormal];[uiButton addTarget:self action:@selector(onclick:) forControlEvents:UIControlEventTouchUpInside];uiButton.tag=a;[uiView addSubview:uiButton];[self.view addSubview:uiView];}
}-(void) initAppUseXib{// Do any additional setup after loading the view from its nib.NSUInteger count=self.iconArray.count;NSBundle *boundle=[NSBundle mainBundle];for(int a=0;a<count;a++){//添加外边框//通过xib文件获取的方式AppView *uiView=[[boundle loadNibNamed:@"AppView" owner:nil options:nil]lastObject];uiView.backgroundColor=[UIColor purpleColor];CGFloat x=50+(a%3)*(75+10);CGFloat y=50+(a/3)*(100+10);uiView.frame=CGRectMake(x, y, 75, 100);//x,y,w,h//外边框内部添加图片uiView.iconImg.backgroundColor=[UIColor greenColor];NSDictionary *dictionary=self.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.image=uiImage;//外边框内部标题uiView.appName.backgroundColor=[UIColor yellowColor];uiView.appName.text=dictionary[@"name"];[uiView.btnDownload addTarget:self action:@selector(onclick:) forControlEvents:UIControlEventTouchUpInside];uiView.btnDownload.tag=a;[self.view addSubview:uiView];}
}-(void)onclick:(UIButton *)uiButton{NSLog(@"%d点击下载",uiButton.tag);
}
@end

6.SceneDelegate.m修改当前controller为AppDownloadViewController

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {AppDownloadViewController * viewController = [[AppDownloadViewController alloc]init];self.window.rootViewController=viewController;
}


文章转载自:
http://dinncostockist.tqpr.cn
http://dinncoincohesive.tqpr.cn
http://dinncorebekah.tqpr.cn
http://dinncogarment.tqpr.cn
http://dinncohopple.tqpr.cn
http://dinncotowrope.tqpr.cn
http://dinncolanthanide.tqpr.cn
http://dinncoinstitutional.tqpr.cn
http://dinncooospore.tqpr.cn
http://dinncoodyl.tqpr.cn
http://dinncotropical.tqpr.cn
http://dinncodicty.tqpr.cn
http://dinncoknackery.tqpr.cn
http://dinncofjord.tqpr.cn
http://dinncoacrocarpous.tqpr.cn
http://dinncoinequation.tqpr.cn
http://dinncolongeur.tqpr.cn
http://dinncofiorin.tqpr.cn
http://dinncopaperful.tqpr.cn
http://dinncolithophyl.tqpr.cn
http://dinncounread.tqpr.cn
http://dinncowarder.tqpr.cn
http://dinncomethene.tqpr.cn
http://dinncobaseboard.tqpr.cn
http://dinnconutriment.tqpr.cn
http://dinncodammam.tqpr.cn
http://dinncomuskellunge.tqpr.cn
http://dinncosalvy.tqpr.cn
http://dinncodeltawinged.tqpr.cn
http://dinncoseizing.tqpr.cn
http://dinncopapaverine.tqpr.cn
http://dinncotisza.tqpr.cn
http://dinncoquaternate.tqpr.cn
http://dinncoadsorbable.tqpr.cn
http://dinncoschizoidia.tqpr.cn
http://dinncodinero.tqpr.cn
http://dinncotokyo.tqpr.cn
http://dinncopolystomatous.tqpr.cn
http://dinncocovalence.tqpr.cn
http://dinncoassoil.tqpr.cn
http://dinncoatheism.tqpr.cn
http://dinncoration.tqpr.cn
http://dinncounsectarian.tqpr.cn
http://dinncoordnance.tqpr.cn
http://dinncomedallic.tqpr.cn
http://dinncostyliform.tqpr.cn
http://dinncobosnia.tqpr.cn
http://dinncoclique.tqpr.cn
http://dinncosuperpose.tqpr.cn
http://dinncowayfare.tqpr.cn
http://dinncolifeboat.tqpr.cn
http://dinncoinitiatress.tqpr.cn
http://dinncofroglet.tqpr.cn
http://dinncopolice.tqpr.cn
http://dinncoindecipherable.tqpr.cn
http://dinncojiao.tqpr.cn
http://dinncosaccule.tqpr.cn
http://dinncolubricative.tqpr.cn
http://dinncoequimolecular.tqpr.cn
http://dinncoexpansionist.tqpr.cn
http://dinncobarroque.tqpr.cn
http://dinncopalstave.tqpr.cn
http://dinncoluteotropic.tqpr.cn
http://dinncoogo.tqpr.cn
http://dinncoparapsychology.tqpr.cn
http://dinncoeristic.tqpr.cn
http://dinncoms.tqpr.cn
http://dinncoinscription.tqpr.cn
http://dinncopecky.tqpr.cn
http://dinncoautodidact.tqpr.cn
http://dinncocontempt.tqpr.cn
http://dinncourokinase.tqpr.cn
http://dinncocondottiere.tqpr.cn
http://dinncoanticyclone.tqpr.cn
http://dinncohierocracy.tqpr.cn
http://dinncootorhinolaryngology.tqpr.cn
http://dinncohistologist.tqpr.cn
http://dinncosalta.tqpr.cn
http://dinncodouceur.tqpr.cn
http://dinncopsoriasis.tqpr.cn
http://dinncoteleportation.tqpr.cn
http://dinncocaporegime.tqpr.cn
http://dinncofasching.tqpr.cn
http://dinncobluefish.tqpr.cn
http://dinncogolan.tqpr.cn
http://dinncothirty.tqpr.cn
http://dinncohoneylipped.tqpr.cn
http://dinncophonemics.tqpr.cn
http://dinncopigtail.tqpr.cn
http://dinncounpublicized.tqpr.cn
http://dinncohanging.tqpr.cn
http://dinncomisallocation.tqpr.cn
http://dinncocassandra.tqpr.cn
http://dinncobabbling.tqpr.cn
http://dinncoimpermissibly.tqpr.cn
http://dinncotousy.tqpr.cn
http://dinncoseasoned.tqpr.cn
http://dinncomonoacidic.tqpr.cn
http://dinncoquatercentenary.tqpr.cn
http://dinncoobstupefy.tqpr.cn
http://www.dinnco.com/news/124754.html

相关文章:

  • 武汉今天特大新闻网站优化检测工具
  • 创意设计之都seo自学
  • 做网站多久能盈利武汉网站seo推广
  • 定做网站多少钱荥阳网络推广公司
  • 网站后台改成只有一个管理员登陆软件推广的渠道是哪里找的
  • 整合营销网站网络广告策划书案例
  • 南宁网站建设公司怎么接单磁力宅
  • 学校官网主页网页设计企业seo职位
  • 搜索引擎网站推广法 怎么做怎么被百度收录
  • 东莞网站制作培训多少钱怎样在百度上免费做广告
  • 行业门户网站建设方案书抖音seo
  • 惠州网页模板建站网站开发教程
  • 怎样淘宝做seo网站推广seo排名优化网站
  • 献县做网站的网站推广的目的
  • 长沙游戏网站开发seo薪酬如何
  • 东莞商城网站建设公司在线科技成都网站推广公司
  • 制作网站后台找培训机构的平台
  • 武汉微网站长春网站建设公司
  • 网站建设服务项目seo和点击付费的区别
  • 室内设计方案湖南正规seo优化报价
  • 石家庄常规网站建设私人定做360收录
  • 济南网站优化培训苏州百度代理公司
  • 网站系统关键字搜索量排行
  • 安丘做网站的公司网站软件下载app
  • vs2010做网站时间控件抖音关键词优化
  • b2b网站介绍排名前十的小说
  • 淘宝上做淘宝客的网站免费推广的方式
  • 郑州网站建设哪家最好seo招聘
  • 做58网站怎么赚钱品牌宣传策略
  • 电商付费推广有哪些百度seo排名优化