首页 文章 精选 留言 我的

精选列表

搜索[Markdown改进],共10003篇文章
优秀的个人博客,低调大师

ios17--自定义控件2改进

控制器: // // XMGViewController.h #import <UIKit/UIKit.h> @interface XMGViewController : UIViewController@end // // XMGViewController.m #import "XMGViewController.h" #import "XMGShop.h" #import "XMGShopView.h" @interface XMGViewController () @property (weak, nonatomic) IBOutlet UIView *shopCarView; @property (weak, nonatomic) IBOutlet UIButton *addButton; @property (weak, nonatomic) IBOutlet UIButton *removeButton; @property (nonatomic, strong) NSArray *dataArr; @end @implementation XMGViewController /** * 懒加载 */ - (NSArray *)dataArr{ if (_dataArr == nil) { // 加载数据 // 1.获取全路径 NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"shopData.plist" ofType:nil]; self.dataArr = [NSArray arrayWithContentsOfFile:dataPath]; // 字典转模型 // 创建临时数组 NSMutableArray *tempArray = [NSMutableArray array]; for (NSDictionary *dict in _dataArr) { // 创建shop对象 XMGShop *shop = [XMGShop shopWithDict:dict]; // 把模型装入数组 [tempArray addObject:shop]; } self.dataArr = tempArray; } return _dataArr; } // 初始化数据 - (void)viewDidLoad { [super viewDidLoad]; } /** * 添加到购物车 * * @param button 按钮 */ - (IBAction)add:(UIButton *)button { /***********************1.定义一些常量*****************************/ // 1.总列数 NSInteger allCols = 3; // 2.商品的宽度 和 高度 CGFloat width = 80; CGFloat height = 100; // 3.求出水平间距 和 垂直间距 CGFloat hMargin = (self.shopCarView.frame.size.width - allCols * width) / (allCols -1); CGFloat vMargin = (self.shopCarView.frame.size.height - 2 * height) / 1; // 4. 设置索引 NSInteger index = self.shopCarView.subviews.count; // 5.求出x值 CGFloat x = (hMargin + width) * (index % allCols); CGFloat y = (vMargin + height) * (index / allCols); /***********************2.创建一个商品*****************************/ /* 原来的分开创建: // 1.创建商品的view UIView *shopView = [[UIView alloc] init]; // 2.设置frame shopView.frame = CGRectMake(x, y, width, height); // 3.设置背景颜色 shopView.backgroundColor = [UIColor greenColor]; // 4.添加到购物车 [self.shopCarView addSubview:shopView]; // 5.创建商品的UIImageView对象 UIImageView *iconView = [[UIImageView alloc] init]; iconView.frame = CGRectMake(0, 0, width, width); iconView.backgroundColor = [UIColor blueColor]; [shopView addSubview:iconView]; // 6.创建商品标题对象 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.frame = CGRectMake(0, width, width, height - width); titleLabel.backgroundColor = [UIColor yellowColor]; titleLabel.textAlignment = NSTextAlignmentCenter; // 居中 [shopView addSubview:titleLabel]; */ XMGShopView *shopView = [[XMGShopView alloc] init]; shopView.frame = CGRectMake(x, y, width, height); [self.shopCarView addSubview:shopView]; // shopView.titleLabel = nil; /***********************3.设置数据*****************************/ // 设置数据 XMGShop *shop = self.dataArr[index]; /* shopView.iconView.image = [UIImage imageNamed:shop.icon]; shopView.titleLabel.text = shop.name; */ [shopView setIcon:shop.icon]; [shopView setName:shop.name]; /***********************4.设置按钮的状态*****************************/ button.enabled = (index != 5); // 5.设置删除按钮的状态 self.removeButton.enabled = YES; } /** * 从购物车中删除 * * @param button 按钮 */ - (IBAction)remove:(UIButton *)button { // 1. 删除最后一个商品 UIView *lastShopView = [self.shopCarView.subviews lastObject]; [lastShopView removeFromSuperview]; // 3. 设置添加按钮的状态 self.addButton.enabled = YES; // 4. 设置删除按钮的状态 self.removeButton.enabled = (self.shopCarView.subviews.count != 0); } @end 自定义控件: // // XMGShopView.h #import <UIKit/UIKit.h> @interface XMGShopView : UIView // readonly 只会调用get方法 /** 图片控件 */ //@property (nonatomic, weak, readonly) UIImageView *iconView;// [self addSubview:iconView];已经有强指针引用了,这里用weak /** 标题控件 */ //@property (nonatomic, weak, readonly) UILabel *titleLabel; // 提供接口方法 - (void)setIcon: (NSString *)icon; - (void)setName: (NSString *)name; @end // // XMGShopView.m #import "XMGShopView.h" @interface XMGShopView () //扩展属性 @property (nonatomic, strong) UIImageView *iconView;//[self addSubview:iconView];有强指针指向了,用weak @property (nonatomic, strong) UILabel *titleLabel; @end @implementation XMGShopView /** * 初始化子控件(不要设置frame) * */ - (instancetype)init{ if (self = [super init]) { // 1.创建商品的UIImageView对象 UIImageView *iconView = [[UIImageView alloc] init]; iconView.backgroundColor = [UIColor blueColor]; [self addSubview:iconView]; _iconView = iconView; // 2.创建商品标题对象 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.backgroundColor = [UIColor yellowColor]; titleLabel.textAlignment = NSTextAlignmentCenter; // 居中 [self addSubview:titleLabel]; _titleLabel = titleLabel; } return self; } /** * 布局子控件(可以拿到frame) */ - (void)layoutSubviews{ // 0.一定要调用super [super layoutSubviews]; // 1.获取当前控件的尺寸 CGFloat width = self.frame.size.width; CGFloat height = self.frame.size.height; // 2.设置子控件的frame self.iconView.frame = CGRectMake(0, 0, width, width); self.titleLabel.frame = CGRectMake(0, width, width, height - width); } - (void)setIcon:(NSString *)icon{ // 设置数据 self.iconView.image = [UIImage imageNamed:icon]; } - (void)setName:(NSString *)name{ // 设置数据 self.titleLabel.text = name; } @end bean: // // XMGShop.h #import <Foundation/Foundation.h> @interface XMGShop : NSObject /** 图片的名称 */ @property (nonatomic, copy) NSString *icon; /** 商品的名称 */ @property (nonatomic, copy) NSString *name; // 提供构造方法 /* - (instancetype)initWithIcon: (NSString *)icon name: (NSString *)name; + (instancetype)shopWithIcon: (NSString *)icon name: (NSString *)name; */ - (instancetype)initWithDict:(NSDictionary *)dict; + (instancetype)shopWithDict:(NSDictionary *)dict; @end // // XMGShop.m #import "XMGShop.h" @implementation XMGShop /* - (instancetype)initWithIcon:(NSString *)icon name:(NSString *)name{ if (self = [super init]) { self.icon = icon; self.name = name; } return self; } + (instancetype)shopWithIcon:(NSString *)icon name:(NSString *)name{ return [[self alloc] initWithIcon:icon name:name]; } */ - (instancetype)initWithDict:(NSDictionary *)dict{ if (self = [super init]) { self.icon = dict[@"icon"]; self.name = dict[@"name"]; } return self; } + (instancetype)shopWithDict:(NSDictionary *)dict{ return [[self alloc] initWithDict:dict]; } @end 本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/7466778.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

ios18---自定义控件3改进

控制器: // XMGViewController.h #import <UIKit/UIKit.h> @interface XMGViewController : UIViewController @end // XMGViewController.m #import "XMGViewController.h" #import "XMGShop.h" #import "XMGShopView.h" @interface XMGViewController () // 购物车 @property (weak, nonatomic) IBOutlet UIView *shopCarView; // 添加按钮 @property (weak, nonatomic) IBOutlet UIButton *addButton; // 删除按钮 @property (weak, nonatomic) IBOutlet UIButton *removeButton; /** 数据数组 */ @property (nonatomic, strong) NSArray *dataArr; @end @implementation XMGViewController /** * 懒加载,get方法 */ - (NSArray *)dataArr{ if (_dataArr == nil) { // 加载数据 // 1.获取全路径 NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"shopData.plist" ofType:nil]; self.dataArr = [NSArray arrayWithContentsOfFile:dataPath]; // 字典转模型 // 创建临时数组 NSMutableArray *tempArray = [NSMutableArray array]; for (NSDictionary *dict in _dataArr) { // 创建shop对象 XMGShop *shop = [XMGShop shopWithDict:dict]; // 把模型装入数组 [tempArray addObject:shop]; } self.dataArr = tempArray; } return _dataArr; } // 初始化数据 - (void)viewDidLoad { [super viewDidLoad]; } /** * 添加到购物车 * * @param button 按钮 */ - (IBAction)add:(UIButton *)button { /***********************1.定义一些常量*****************************/ // 1.总列数 NSInteger allCols = 3; // 2.商品的宽度 和 高度 CGFloat width = 80; CGFloat height = 100; // 3.求出水平间距 和 垂直间距 CGFloat hMargin = (self.shopCarView.frame.size.width - allCols * width) / (allCols -1); CGFloat vMargin = (self.shopCarView.frame.size.height - 2 * height) / 1; // 4. 设置索引 NSInteger index = self.shopCarView.subviews.count; // 5.求出x值 CGFloat x = (hMargin + width) * (index % allCols); CGFloat y = (vMargin + height) * (index / allCols); /***********************2.创建一个商品*****************************/ /* XMGShopView *shopView = [[XMGShopView alloc] init]; shopView.frame = CGRectMake(x, y, width, height); // 设置数据 XMGShop *shop = self.dataArr[index]; shopView.shop = shop; [self.shopCarView addSubview:shopView]; */ XMGShopView *shopView = [XMGShopView shopViewWithShop:self.dataArr[index]]; shopView.frame = CGRectMake(x, y, width, height); [self.shopCarView addSubview:shopView]; /***********************3.设置数据*****************************/ // 设置数据 // XMGShop *shop = self.dataArr[index]; // [shopView setIcon:shop.icon]; // [shopView setName:shop.name]; /***********************4.设置按钮的状态*****************************/ button.enabled = (index != 5); // 5.设置删除按钮的状态 self.removeButton.enabled = YES; } /** * 从购物车中删除 * * @param button 按钮 */ - (IBAction)remove:(UIButton *)button { // 1. 删除最后一个商品 UIView *lastShopView = [self.shopCarView.subviews lastObject]; [lastShopView removeFromSuperview]; // 3. 设置添加按钮的状态 self.addButton.enabled = YES; // 4. 设置删除按钮的状态 self.removeButton.enabled = (self.shopCarView.subviews.count != 0); } @end 自定义控件: // XMGShopView.h #import <UIKit/UIKit.h> @class XMGShop; @interface XMGShopView : UIView /** 商品模型 */ @property (nonatomic, strong) XMGShop *shop; // 构造方法 - (instancetype)initWithShop: (XMGShop *)shop; + (instancetype)shopViewWithShop: (XMGShop *)shop; @end // XMGShopView.m #import "XMGShopView.h" #import "XMGShop.h" @interface XMGShopView () /** 图片控件 */ @property (nonatomic, weak) UIImageView *iconView; /** 标题控件 */ @property (nonatomic, weak) UILabel *titleLabel; @end @implementation XMGShopView /** * 初始化子控件(不要设置frame) * */ - (instancetype)init{ if (self = [super init]) { [self setUp]; } return self; } //构造方法,对象方法 - (instancetype)initWithShop:(XMGShop *)shop{ if (self = [super init]) { // 注意:先创建后赋值,不然空指针, [self setUp]; self.shop = shop;//调用set方法 } return self; } //构造方法,类方法 + (instancetype)shopViewWithShop:(XMGShop *)shop{ return [[self alloc] initWithShop:shop]; } /** * 初始化 */ - (void)setUp{ // 1.创建商品的UIImageView对象 UIImageView *iconView = [[UIImageView alloc] init]; iconView.backgroundColor = [UIColor blueColor]; [self addSubview:iconView]; _iconView = iconView; // 2.创建商品标题对象 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.backgroundColor = [UIColor yellowColor]; titleLabel.textAlignment = NSTextAlignmentCenter; // 居中 [self addSubview:titleLabel]; _titleLabel = titleLabel; } /** * 布局子控件(可以拿到frame) */ - (void)layoutSubviews{ // 0.一定要调用super [super layoutSubviews]; // 1.获取当前控件的尺寸 CGFloat width = self.frame.size.width; CGFloat height = self.frame.size.height; // 2.设置子控件的frame self.iconView.frame = CGRectMake(0, 0, width, width); self.titleLabel.frame = CGRectMake(0, width, width, height - width); } /** * 重写set方法:只要外边传数据就会调用 * 作用:设置数据 */ - (void)setShop:(XMGShop *)shop{ _shop = shop; // 设置数据 self.iconView.image = [UIImage imageNamed:shop.icon]; self.titleLabel.text = shop.name; } @end bean: // XMGShop.h #import <Foundation/Foundation.h> @interface XMGShop : NSObject /** 图片的名称 */ @property (nonatomic, copy) NSString *icon; /** 商品的名称 */ @property (nonatomic, copy) NSString *name; // 提供构造方法 /* - (instancetype)initWithIcon: (NSString *)icon name: (NSString *)name; + (instancetype)shopWithIcon: (NSString *)icon name: (NSString *)name; */ - (instancetype)initWithDict:(NSDictionary *)dict; + (instancetype)shopWithDict:(NSDictionary *)dict; @end // XMGShop.m #import "XMGShop.h" @implementation XMGShop /* - (instancetype)initWithIcon:(NSString *)icon name:(NSString *)name{ if (self = [super init]) { self.icon = icon; self.name = name; } return self; } + (instancetype)shopWithIcon:(NSString *)icon name:(NSString *)name{ return [[self alloc] initWithIcon:icon name:name]; } */ - (instancetype)initWithDict:(NSDictionary *)dict{ if (self = [super init]) { self.icon = dict[@"icon"]; self.name = dict[@"name"]; } return self; } + (instancetype)shopWithDict:(NSDictionary *)dict{ return [[self alloc] initWithDict:dict]; } @end 本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/7466861.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Microsoft 对 Node.js 改进以支持 ARM

Node.js 支持多种不同的平台,但是 ARM 上的 Windows 不在其中。为了解决这个问题,微软创建了自己的一个 Node.js 版本,其目的是为了支持 ARM 架构下运行的 Windows 10 操作系统。 为了完成这个要求,微软将 Node.js 默认的 V8 引擎改为在 Windows 10 上的 Chakra 引擎。因此,微软的 Node.js 版本跟标准的 Node.js 版本会有所区别,微软也声称希望将这些变化合并到 Node.js 的主分支上。 支持 ARM 上的 Windows 10 是微软物联网战略的重要一个环节,其修改的 Node.js 版本将可以运行在任意版本的 Windows 10 上,团队已经提供了一个 示例 来运行 Windows Universal “Hello, World” 应用以及在树莓派 2 上如何修改 项目 。文章转载自 开源中国社区 [http://www.oschina.net]

优秀的个人博客,低调大师

Markdown中的特色图标是什么,有什么参考教程吗?

作者:三十三重天 博客: http://www.zhouhuibo.club 我们在观察别人的文章时候时,总能看到很多有趣的图标,像是这样 😀🤣又或是🌸🌃🍀这样 。当我们复制图标时发现直接ctrl+c ctrl+v就可以,这竟然不是图片,而是一种字符,字符怎么能是图片呢,带着疑问我们先来看看这到底是什么。 经过查询,发现这种文本类型的象形符号是有官方定义的名称的,叫做Emoji 什么是Emoji Emoji是一种文本类型的象形符号, 它和图片、表情包不同,它能够在任何文本输入的地方使用,因为它本身就是一种文字 ;最新的emoji 13.0版本包含1814个独立的表情符号(该统计不包含由多符号组成和其他肤色的表情符号), emoji能够在各个不同的操作平台上显示,但显示效果会有一些不同: 它最早出现于日本,日本称它为“绘文字(日语:絵文字/えもじ emoji)”,由栗田穰崇(Shigetaka Kurita)创作,并在全球网络及手机用户中流行。全球约有90%的在线用户频繁使用emoji,每天有60亿个emoji表情符号被传送。纽约现代艺术博物馆将emoji列为永久收藏,其中包括176个诞生于1999年的最初版本emoji表情。 Emoji发明的初衷是为了让人们的表达更加的多样化和趣味性,发展到现在更像是一种新的语言,并有自己独特的魅力,它在我们日常的网络聊天中随处可见,通过它你可以了解到行行文字后的感情,甚至于一个emoji就可以表达我们当下的心情, 统一码联盟(Unicode Consortium)每年都会推出许多新的emoji,大家只要及时更新自己的操作系统,就可以更好的显示这些又新又有趣的emoji了。 未来emoji的使用将会越来越广泛,这是趋势也是必然。 Unicode和Emoji的联系 Unicode(中文:万国码、国际码、统一码、单一码)是计算机科学领域里的一项业界标准。字符编码是在Unicode编码方案下规定的分配给每个Unicode字符的唯一数字。如果没有它,同一个编码在不同的电脑和平台上会被解读成不同的字符。 Unicode广泛应用在计算机、互联网、编程语言和现代操作系统中, 它使得各种文字在不同的平台上能够兼容,并统一的呈现 。 而Emoji进入Unicode是其重要的转折点,在此之前,emoji由各个不同的厂商自行创造,这使得emoji在不同厂商的设备间无法兼容,直接导致了人们在不同的设备上没法用emoji交流,为此,Unicode联盟为Emoji专门组建了一个委员会Emoji Subcommittee来统一和规范Emoji, 统一码联盟(Unicode Consortium)每年都会发布新版本的Unicode,而伴随着它的版本更新,新的emoji也会应运而生。目前Unicode在最新版中增加了新的第3种性别“中性”、以及奶茶和忍者等全新的emoji。 有什么平台可以检索emoji吗? 答案是当然的。重点推荐Emoji中文网-传送门。 Emoji中文网是一个Web网站,拥有最全最详细的Emoji图标,同时支持分类、检索、专栏推荐、Emoji小游戏等功能。我们先看看网站的首页 左侧导航 左导航栏是对Emoji图标的分类,不同分类的表情个数,分类名称都有显示。 详情页 可以通过各种类型的图标查看图标的使用情况,热门排行 热门专题 将最热门的表情以一个集锦的方式供用户挑选。 知识检索 使用关键词检索出内容,支持中文,英文检索。 还在等什么,快快登录检索符合自己的Emoji图标吧。 最后 关注公众号 程序员工具集 👍👍 致力于分享优秀的开源项目、学习资源 、常用工具 回复关键词“关注礼包”,送你一份最全的程序员技能图谱。 回复关键词"wx"添加个人微信,勾搭作者,欢迎来聊^-^。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册