当前位置:网站首页>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 .
边栏推荐
- You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
- [paper notes] catching both gray and black swans: open set supervised analog detection*
- kibana 重建index后,如何恢复Visualizations和 Dashboards
- After easynvr video is enabled, no video file is generated. How to solve this problem?
- Tensorboard的使用
- There are some limitations in cluster expansion and contraction
- Basic use of check boxes and implementation of select all and invert selection functions
- Use of tensorboard
- Object.defineProperty() 和 数据代理
- Map接口及其子实现类
猜你喜欢

Vulnhub | DC: 4 |【實戰】

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

渲染效果图哪家好?2022最新实测(四)

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

What are open source software, free software, copyleft and CC? Can't you tell them clearly?

Tensorboard的使用

Introduction to typescript and basic types of variable definitions

Why use growth neural gas network (GNG)?

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

transform的结构及用法
随机推荐
Does huangrong really exist?
顺序表课设
力扣(LeetCode)173. 二叉搜索树迭代器(2022.06.22)
如何在conda虚拟环境开启jupyter-notebook
Apache Solr arbitrary file read replication
Vulnhub | dc: 3 | [actual combat]
Tensorboard的使用
Why do we say that the data service API is the standard configuration of the data midrange?
RTSP/ONVIF协议视频平台EasyNVR启动服务报错“service not found”,该如何解决?
Idea true permanent activation method and permanent activation code tutorial
词性家族
typeScript的介绍与变量定义的基本类型
Easygbs cannot play video streams in webrtc format. What is the reason?
Ad object of Active Directory
C Advanced Learning -- extended method (this)
Odoo project sends information to wechat official account or enterprise wechat
Tencent cloud account related
Observer mode
开源技术交流丨批流一体数据同步引擎ChunJun数据还原-DDL功能模块解析
Integers and operators in go data types (3)