Create Vertical lines between Uilabels inside of a stack view [duplicate]

对着背影说爱祢 提交于 2019-12-04 06:52:11

If you do that in interface builder it can be very easy. Add you labels to horizontal stack view, then add your divider views in between, create 1 point width constraint for your divider views, set their hugging priority higher than your labels and set your stack view's alignment to fill and distribution to equal spacing. That's it. You may also want to set the dividers' width constraint priority to 999 so the xcode wont complain for breaking constraints in some cases.

here're a screenshot of my quick test:

and the result in the simulator:

My example is done straight in a view of a view controller, but you of course can create a new UIView subclass with a xib file, put the labels (and dividers) in there and later instantiate your view something like this: let myView = Bundle.main.loadNibNamed("MyViewWithLabels", owner: nil, options: nil)![0] as! MyViewWithLabels. Then just add your view instance to your collection view cll as a subview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!