简体   繁体   中英

Add CollectionView or ViewController to AlertView

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:

  • How to change the buttons size to fit in one line but do not affect the textfield size
  • Or how to add the collection view to an alert view so I have the action button easier??

要将按钮设置为一行,您需要更新按钮约束。将两个按钮的宽度都设置为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM