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

创建手机网页市场seo是什么意思

创建手机网页,市场seo是什么意思,网站建设销售ppt模板,大型网站后台是java吗需求分析: 标签根据文字长度,自适应标签居中显示扩展 超过内容显示范围,需要换行显示,且保持居中显示 AI实现过程 提问: 回答: import UIKit import SnapKitclass DynamicLabelsContainerView: UIView…

在这里插入图片描述

需求分析

  1. 标签根据文字长度,自适应
  2. 标签居中显示
  3. 扩展 超过内容显示范围,需要换行显示,且保持居中显示

AI实现过程

提问:

在这里插入图片描述

回答:
在这里插入图片描述

import UIKit
import SnapKitclass DynamicLabelsContainerView: UIView {private let horizontalSpacing: CGFloat = 8.0private let verticalSpacing: CGFloat = 4.0// 初始化方法override init(frame: CGRect) {super.init(frame: frame)}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}// 配置容器视图func configure(with strings: [String]) {// 先清除所有子视图self.subviews.forEach { $0.removeFromSuperview() }var lastLabel: UILabel? = nilvar isFirstLabelInLine = truefor string in strings {let label = UILabel()label.text = stringlabel.backgroundColor = .lightGray // 仅为了可视化,实际使用时可移除label.numberOfLines = 1self.addSubview(label)label.snp.makeConstraints { make inif let lastLabel = lastLabel {make.top.equalTo(isFirstLabelInLine ? lastLabel.snp.bottom : lastLabel.snp.top).offset(isFirstLabelInLine ? verticalSpacing : 0)make.left.equalTo(isFirstLabelInLine ? self.snp.left : lastLabel.snp.right).offset(horizontalSpacing)} else {make.top.equalTo(self.snp.top).offset(verticalSpacing)make.left.equalTo(self.snp.left).offset(horizontalSpacing)}// 确保标签不会超出容器视图的宽度make.right.lessThanOrEqualTo(self.snp.right).offset(-horizontalSpacing)}// 使用布局完成回调来决定是否需要换行label.snp.makeConstraints { make inmake.width.equalTo(label.intrinsicContentSize.width).priority(.high)}// 强制立即布局以获取label的frameself.layoutIfNeeded()// 检查是否需要换行if label.frame.maxX > self.bounds.width {isFirstLabelInLine = truelabel.snp.remakeConstraints { make inmake.top.equalTo(lastLabel?.snp.bottom ?? self.snp.top).offset(verticalSpacing)make.left.equalTo(self.snp.left).offset(horizontalSpacing)make.width.equalTo(label.intrinsicContentSize.width).priority(.high)}} else {isFirstLabelInLine = false}lastLabel = label}// 更新容器视图的高度约束以适应所有标签self.snp.makeConstraints { make inmake.bottom.equalTo(lastLabel?.snp.bottom ?? self.snp.top).offset(verticalSpacing)}}
}

验证

在这里插入图片描述

问题:

  • 超出范围没有换行展示

解决:
将下面这句代码注释
在这里插入图片描述

验证:

在这里插入图片描述
问题:

  • 第二排第二个label的布局有问题

解决问题后的最终代码:

import UIKit
import SnapKitclass DynamicLabelsView: UIView {private let horizontalSpacing: CGFloat = 8.0private let verticalSpacing: CGFloat = 4.0// 初始化方法override init(frame: CGRect) {super.init(frame: frame)}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}// 配置容器视图func configure(with strings: [String]) {// 先清除所有子视图self.subviews.forEach { $0.removeFromSuperview() }var lastLabel: UILabel? = nilfor string in strings {let label = UILabel()label.text = stringlabel.backgroundColor = .lightGray // 仅为了可视化,实际使用时可移除label.numberOfLines = 1self.addSubview(label)label.snp.makeConstraints { make inif let lastLabel = lastLabel {make.top.equalTo(lastLabel.snp.top).offset(0)make.left.equalTo(lastLabel.snp.right).offset(horizontalSpacing)} else {make.top.equalTo(self.snp.top).offset(verticalSpacing)make.left.equalTo(self.snp.left).offset(horizontalSpacing)}}// 使用布局完成回调来决定是否需要换行label.snp.makeConstraints { make inmake.width.equalTo(label.intrinsicContentSize.width).priority(.high)}// 强制立即布局以获取label的frameself.layoutIfNeeded()// 检查是否需要换行if label.frame.maxX > self.bounds.width {label.snp.remakeConstraints { make inmake.top.equalTo(lastLabel?.snp.bottom ?? self.snp.top).offset(verticalSpacing)make.left.equalTo(self.snp.left).offset(horizontalSpacing)make.width.equalTo(label.intrinsicContentSize.width).priority(.high)}}lastLabel = label}// 更新容器视图的高度约束以适应所有标签self.snp.makeConstraints { make inmake.bottom.equalTo(lastLabel?.snp.bottom ?? self.snp.top).offset(verticalSpacing)}}
}

效果:

在这里插入图片描述

总结

到这里我们通过AI快速实现了动态标签控件的核心部分,只需再稍微调整一下label的样式就能完美实现我们的需求。AI帮我们写了大部分的可用的代码,虽然不能完全采用,但是确实提升了我们的开发效率,代码质量也是很不错的,我们要做的就是根据自己的需求进行修改一下。后面继续在实战中探索如何高效使用AI来帮助我们开发和学习。


感谢您的阅读和参与,HH思无邪愿与您一起在技术的道路上不断探索。如果您喜欢这篇文章,不妨留下您宝贵的赞!如果您对文章有任何疑问或建议,欢迎在评论区留言,我会第一时间处理,您的支持是我前行的动力,愿我们都能成为更好的自己!

http://www.hkea.cn/news/357666/

相关文章:

  • 曹鹏wordpress建站seo视频广东疫情防控措施
  • 网站开发的岗位排名优化工具
  • 岳阳做网站怎么做推广让别人主动加我
  • 不断改进网站建设公司百度官网优化
  • 万户网站宁波网站制作优化服务
  • 潍坊快速网站排名网站是怎么做出来的
  • 聚美优品的pc网站建设注册网址
  • 陕西省住房与城乡建设厅网站免费b站推广软件
  • 淮南市住房与城乡建设部网站网店买卖有哪些平台
  • 网页qq表情佛山百度快速排名优化
  • 网站建设方案论文1500社会新闻最新消息
  • 网站组建 需求分析市场监督管理局职责
  • 云课堂哪个网站做的好厦门关键词优化seo
  • 中企动力沈阳分公司seo免费诊断电话
  • 网站vps被黑湖人最新排名最新排名
  • 如何夸奖客户网站做的好seo课程心得体会
  • 有哪些做电子商务的网站时空seo助手
  • 临沂百度网站电脑培训机构哪个好
  • 无锡专业做网站的公司怎样把自己的产品放到网上销售
  • 大学网站建设管理办法推广技巧
  • 长春做网站公司seo关键词排名优化软件怎么选
  • 网站开发未按合同约定工期完工seo关键词排名怎么提升
  • 创可贴app海报制作网站百度seo优化方法
  • 龙岗品牌网站建设2024年新闻摘抄
  • 南阳住房和城乡建设厅网站招聘网站排名
  • 如何做网站活动封面建站的公司
  • 温州网站建设培训营销推广方案包括哪些内容
  • 厦门 建网站商业软文案例
  • wordpress读者墙站长之家seo工具包
  • 网站建设哪家好灵活苏州久远网络北京搜索引擎关键词优化