当前位置:网站首页>Arclayoutview: implementation of an arc layout
Arclayoutview: implementation of an arc layout
2022-06-23 08:24:00 【the Summer Palace】
Introduce
If in a project , Designers let you achieve this effect :

Will this drive you crazy ? Don't worry. , We can use ArcLayoutView. Project address :https://gitee.com/kmyhy/arc-view
usage
There's only one file :ArcLayoutView.swift, Just put it in your project :)
Two macros may not be found during compilation , You can ViewController.swift Find them in :
let SCREEN_HEIGHT = UIScreen.main.bounds.height
let SCREEN_WIDTH = UIScreen.main.bounds.width
And one. UILabel An extension of :
extension UILabel {
func getSize(constrainedWidth: CGFloat) -> CGSize {
return systemLayoutSizeFitting(CGSize(width: constrainedWidth, height: UIView.layoutFittingCompressedSize.height), withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
}
}
Then you can create a ArcLayoutView Object and add it to your ViewController It's in ( Story board or code addition ). If you use a story board , So don't forget to create the corresponding IBOutlet Variable :
@IBOutlet weak var arcView: ArcLayoutView!
Then you need to make view controller To achieve ArcLayoutViewDelegate agreement , It contains 3 A way :
extension ViewController: ArcViewDelegate {
func itemView(_ index: Int) -> UIView {
let itemView = CustomItemView(frame: .zero)
itemView.titleLabel.text = titles[index]
itemView.backgroundColor = .clear
itemView.detailLabel.text = details[index]
return itemView
}
func itemViewSize(_ itemView: UIView, limitWidth: CGFloat) -> CGSize {
let v = itemView as! CustomItemView
var labelSize = v.titleLabel.getSize(constrainedWidth: limitWidth-48)
var h = labelSize.height
labelSize = v.detailLabel.getSize(constrainedWidth: limitWidth-48)
h += labelSize.height+2
print(h)
return CGSize(width: limitWidth, height: h)
}
func itemCount() -> Int {
return titles.count
}
}
among ,CustomItemView It's a UIView Or custom UIView Subclass . Whether you use pure code or xib Can be created , Whatever you like .
The first delegate method needs to return a UIView object , For this example , That is to say CustomItemView Object ( This is a ArcLayoutView Of ItemView, It is the sub view, At the same time, they are responsible for layout ) . You also need to render the data in this method .
The second delegate method needs to return CGSize , Used to tell ArcLayoutView Every ItemView How much space does it take . If ItemView Adaptive , You need to calculate its size correctly and return it to ArcLayoutView.
The last delegate method returns Int, Used to tell ArcLayoutView It needs to show how many ItemView.
Okay , Let's go view controller Designated as ArcLayoutView Commission of :
arcView.options.alignment = .middle
arcView.delegate = self
ArcLayoutView Of options Property is a ArcLayoutViewOptions Structure . It provides a lot for controlling ArcLayoutView Layout and appearance options . such as alignment Used to specify its location in the layout ItemView The alignment of , have access to .top, .middle and .bottom. If you use .middle , So it looks like this :

Pay attention to this line :
arcView.delegate = selfIt can lead to ArcLayoutView Redraw all of itItemView.
ArcLayoutViewOptions One more itemAlignment attribute , Is used to specify the ItemView How itself is aligned to the anchor anchor Of . Anchor point , In fact, they are the red dots in the picture . The default value of this attribute is .middle.
If you set options.alignment = .top, So it looks like this :

Two adjacent ItemView The vertical spacing between them is equal , You can go through ArcLayoutViewOptions Of itemVerticalSpan Attribute adjustment .
If you don't need to draw an arc 、anchor And spokes , You can modify these properties :
arcView.options.showDot = false
arcView.options.showArc = false
arcView.options.showSpokes = false
It looks like this :

For more details , Please check the source code .
边栏推荐
- Location of firewalld configuration file
- RTSP/ONVIF协议视频平台EasyNVR启动服务报错“service not found”,该如何解决?
- C print zoom
- Easygbs cannot play video streams in webrtc format. What is the reason?
- Vulnhub | dc: 3 | [actual combat]
- Vulnhub | DC: 3 |【实战】
- Moodle e-learning platform fixes the session hijacking error that leads to pre authorized rce
- Implementation of AVL tree
- 图像分割-改进网络结构
- 谈谈 @Autowired 的实现原理
猜你喜欢
![[paper notes] catching both gray and black swans: open set supervised analog detection*](/img/52/787b25a9818cfc6a1897af81d41ab2.png)
[paper notes] catching both gray and black swans: open set supervised analog detection*
![Vulnhub | dc: 3 | [actual combat]](/img/97/e5ba86f2694fe1705c13c60484cff6.png)
Vulnhub | dc: 3 | [actual combat]

自组织映射神经网络(SOM)

Why do we say that the data service API is the standard configuration of the data midrange?

typeScript的介绍与变量定义的基本类型

鸿蒙读取资源文件

论文阅读【Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset】

Create an orderly sequence table and perform the following operations: 1 Insert element x into the table and keep it in order; 2. find the element with the value of X, and delete it if found; 3. outpu

Tensorboard的使用

看了5本书,我总结出财富自由的这些理论
随机推荐
Imperva- method of finding regular match timeout
自组织映射神经网络(SOM)
typeScript的介绍与变量定义的基本类型
通信方式总结及I2C驱动详解
2 corrections de bogues dans l'outil aquatone
Introduction to typescript and basic types of variable definitions
3-ProgressBar和二次裁剪
看了5本书,我总结出财富自由的这些理论
1-渐变、阴影和文本
Keng dad's "dedication blessing": red packet technology explosion in Alipay Spring Festival Gala
View the file once a second and send the result of the last line of the file to the syslog server
Derivation and loading of the trained random forest model
开源技术交流丨批流一体数据同步引擎ChunJun数据还原-DDL功能模块解析
What is a dedicated server line
生产环境服务器环境搭建+项目发布流程
正则表达式使用案例
Google common syntax
Dongyuhui, the "square face teacher", responded that the popularity was declining: do a good job of live broadcasting of agricultural products to benefit farmers and consider supporting education
Go language basic conditional statement if
Go 数据类型篇(二)之Go 支持的数据类型概述及布尔类型