I have a collection view like this:
include textfields and buttons. I presented this view as a popover but the problem is I want the buttons to be on one line (button is also a cell of collection view) so there are 2 questions:
要将按钮设置为一行,您需要更新按钮约束。将两个按钮的宽度都设置为Equal Width并将两个按钮的顶部,底部约束对齐。
Pull both of your button to a stackView and draw only one button's width and height constraint and make the other follow the previous button's width and height. stackView will do the rest of the work.
Don't forget to add constraint for stackView though. :)
I just pull width and height constraint to the first button and from stackView view i set fill equally and interdistance 10
Have you tried implementing a UICollectionViewDelegateFlowLayout
?
If not, try doing that and add the method
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// Implement the code here, check if the indexPaths belong to the buttons,
// And make it return a Size which has a width that is half of the CollectionView width (minus the padding between cells).
}
This lets the CollectionView place them side by side because it'll have enough space for both of them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.