uicollectionview

How to add an UICollectionViewLayout programmatically?

余生颓废 提交于 2020-01-02 12:17:12
问题 I'm trying to setup a UICollectionViewLayout programmatically. I'm using a UICollectionView also without using storyboards, as well as settings its constraints. I've followed Ray Wenderlich tutorial on the subject with some changes to adapt the code to Swift 3 (as AZCoder2 did https://github.com/AZCoder2/Pinterest). Since all these examples uses storyboards, I've also introduced some changes to create the UICollectionView and its UICollectionViewLayout : collectionViewLayout = PinterestLayout

UIRefreshControl with low height UICollectionView

好久不见. 提交于 2020-01-02 09:59:19
问题 I have a view which contains another view on the top part, which I'm using to show some basic information. It has about 40% of the total view height. Below that "header" view, I'm using a UICollectionView which is scrollable. Now I've added a UIRefreshControl to my UICollectionView, but refreshing does never occur, because the user can't pull down the UICollectionView that far. When I reduce the height of the top view, it starts working because there's enough space to pull the collectionview

UICollectionView - draw a line between cells

强颜欢笑 提交于 2020-01-02 09:55:39
问题 How do I draw a line between cells in a UICollectionView that crosses over the spaces? The intended output is something like this.: The best that I've done is to add lines inside each cell. How do I connect the lines through the spaces? 回答1: I made an extension that you can use like this: collectionView.drawLineFrom(indexPathA, to: indexPathB, color: UIColor.greenColor()) Here is the extension: extension UICollectionView { func drawLineFrom( from: NSIndexPath, to: NSIndexPath, lineWidth:

nil label for custom UICollectionCell

不羁的心 提交于 2020-01-02 08:57:28
问题 EDIT : seems like same question as this I made collection view with custom layout and cell but my cell's positions were a little off so I decided to number them so that I could debug it easier. I followed this guy's answer to number my cell using labels. Somehow myLabel was nil and caused my app to crash. I believe I have connected the outlets correctly but maybe someone could provide a list for me to check if I am doing anything wrong. ViewController import UIKit class ViewController:

Multiple cells for a single UICollectionView

这一生的挚爱 提交于 2020-01-02 08:15:11
问题 In my collection view, the cell class must have completely different appearance for different kinds of data in the array. I am looking for a way to create multiple cells and choose a different one according to the input data, so for example : internal func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell1 = collectionView.dequeueReusableCell.. as! kind1 let cell2 = collectionView.dequeueReusableCell.. as! kind2 // here

Set/Override Padding In UICollectionView Between Cells

随声附和 提交于 2020-01-02 08:10:59
问题 I have a UICollectionView and I'm running into an issue with getting the padding between cells. In theory, I should be able to divide the screen by 4, and I can get a cellsize that has 4 images which perfectly take up the screen width. But, it chooses not to do that. Instead it creates 3 images with HUGE padding as shown below: _cellSize = CGSizeMake(UIScreen.mainScreen().bounds.width/4,UIScreen.mainScreen().bounds.width/4) So I decreased the cell size a bit to create some padding, and this

Is it possible to zoom UICollectionView as a unit?

别说谁变了你拦得住时间么 提交于 2020-01-02 06:20:45
问题 We have a level map view in our latest project. It includes the level markers as UICollectionViewCells and various UICollectionReusableViews for fun decoration. We would like to be able to zoom in / out (it is a big map). I had hoped I could make use of the internal UIScrollView to do so, however, you can't zoom yourself... only a subview. Is there anyway to do this outside of individually scaling and relocating each element as I zoom? Feels like it should be a common thing and thus a more

Is it possible to zoom UICollectionView as a unit?

最后都变了- 提交于 2020-01-02 06:20:13
问题 We have a level map view in our latest project. It includes the level markers as UICollectionViewCells and various UICollectionReusableViews for fun decoration. We would like to be able to zoom in / out (it is a big map). I had hoped I could make use of the internal UIScrollView to do so, however, you can't zoom yourself... only a subview. Is there anyway to do this outside of individually scaling and relocating each element as I zoom? Feels like it should be a common thing and thus a more

Indexpath of the button from UICollectionView

陌路散爱 提交于 2020-01-02 03:11:09
问题 I tried to: - (IBAction)delete:(UIButton*)sender{ NSIndexPath *indexPath = [self.collectionView indexPathForCell:(TourGridCell *)[[[sender superview]superview]superview]]; } But NSLog shows that cell exist, but indexpath is nil. 回答1: OK, here it is: - (IBAction)delete:(UIButton *)sender{ NSIndexPath *indexPath = nil; indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]]; } 回答2: Sometimes it's the simplest possible

How to insert images in uicollectionview programmatically?

守給你的承諾、 提交于 2020-01-01 20:49:20
问题 I'm pretty new to Objective-C so hopefully this all makes sense..I ran code provided in first answer Creating a UICollectionView programmatically..It is working fine .Now i want to add some pictures in cell that can expanded by mouse click .I searched many tutorial but all using nib files or storyboard files .How i can accomplish this task programmatically ? Any help would be greatly appreciated. Thanks in advance. 回答1: Beginner read tutroial and understand first everyting in below link and