uicollectionviewcell

UICollectionViewCell dynamic height with autolayout

[亡魂溺海] 提交于 2019-11-27 05:58:30
问题 I am using auto layout with UICollectionViewCell. So the idea is to allow CollectionViewCell to determine it's size based on layouts. All the constraints are set properly but the problem is that I can not calculate it's size for data source method collectionView:layout:sizeForItemAtIndexPath: Ideally I would like to calculate Cell's height doing the following: static MyCell *myCell = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ myCell = [[MyCell alloc] initWithFrame

Resize UICollectionView cells after their data has been set

痞子三分冷 提交于 2019-11-27 05:13:43
问题 My UICollectionView cells contain UILabels with multiline text. I don't know the height of the cells until the text has been set on the label. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; This was the initial method I looked at to size the cells. However, this is called BEFORE the cells are created out of the storyboard. Is there a way to layout the collection and size the cells

Add button at the end of collection view in storyboard

空扰寡人 提交于 2019-11-27 03:40:12
问题 I have a UICollectionViewController in a storyboard. I know how to add cells and modify them but for some reason I can't add any other view or UI element after my UICollectionView . Is there a way to do this in the storyboard? If not how can I do this programmatically? 回答1: In storyboard you can enable it by selecting the radio button title "Section Footer", for your UICollectionView and then by dragging UIButton there. You can also override this function: - (UICollectionReusableView *

Why is UICollectionViewCell's outlet nil?

大城市里の小女人 提交于 2019-11-27 02:41:10
I have created a custom UICollectionViewCell in Interface Builder, binded views on it to the class, and then when I want to use and set a string to the label on the string, tha label has a nil value. override func viewDidLoad() { super.viewDidLoad() // Register cell classes self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls") } override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! { var cell: LeftMenuCollectionViewCell cell = collectionView

Change Background of UICollectionView Cell on Tap

青春壹個敷衍的年華 提交于 2019-11-27 00:53:20
问题 I have a UICollectionView that I have created programmatically. I would like for the collection view to behave in the following way: 1. User touches cell 2. Cell background color changes 3. User releases touch 4. Cell background color changes This should be a quick color change that happens just before the selector related to the tap action is executed in which the viewcontroller containing the collection view is popped off the stack. I have been looking at this question: UICollectionView

How to change UICollectionViewCell size programmatically in Swift?

余生长醉 提交于 2019-11-27 00:16:35
问题 I have a UICollectionView with a segmented control to switch between data. But how do I change the UICollectionViewCell size properties programmatically ? then I can custom each style appropriately for each data type. For example change the width to 520 points and height to 100. I am new to iOS development and am experienced with CSS :/ I know how to do it in Xcode (obviously) but do not know the correct methods to change it in swift. Any ideas or feedback is much appreciated (Y) 回答1: Make

UICollectionView's cell disappearing

孤人 提交于 2019-11-27 00:13:20
What's happening Currently I have an application that uses two UICollectionViews inside a UITableView . This way I create a Pulse News look like application. My problem with this is that sometimes the 6th and 11th row disappears completely, leaving a blank space where it should be the cell. I wouldn't actually mind, if all the cells were like this (and this way I could assume that I wasn't doing things correctly), but the thing is, is just happening with those specific ones. My theory The 6th and 11th rows are the ones that appears when I start scrolling, so by default I am able to see 5 cells

Auto Layout in UICollectionViewCell not working

若如初见. 提交于 2019-11-26 23:44:24
I have a simple UICollectionView with cells that have a single UITextView. The UITextView is constrained to the edges of the cell, so they should stay the same size as the cell size. The problem I'm having is that for some reason these constraints are not working when I specify the cell size via collectionView:layout:sizeForItemAtIndexPath:. I have the cell size set to 320x50 in the Storyboard. If I return a size with 2 times the height of the cell size with sizeForItemAtIndexPath:, the UITextView stays the same height despite the constraints I set. I am using Xcode 6 GM. My view controller

UICollectionView Set number of columns

社会主义新天地 提交于 2019-11-26 23:23:03
I just started learning about UICollectionViews. I'm wondering if anyone knows how to specify the number of columns in a collectionview. The default is set to 3 (iPhone/portrait). I've looked at the documentation and can't seem to find a concise answer. CollectionViews are very powerful, and they come at a price. Lots, and lots of options. As omz said: there are multiple ways you could change the number of columns I'd suggest implementing the <UICollectionViewDelegateFlowLayout> Protocol, giving you access to the following methods in which you can have greater control over the layout of your

Access Firebase variable outside Closure

狂风中的少年 提交于 2019-11-26 23:19:27
I'm trying to use Firebase to set the number of cells in my CollectionView. I tried to create a local variable and set that to the same value as the Firebase variable but when I try use it outside the function it doesn't work. I also tried setting it in ViewWillAppear but it didn't work. I set the nav bar title to view the value. When it was set in the closure I got the correct value, when I wrote that outside the closure (after the firebase function), it gave a value of 0. I'm using swift 3 override func viewWillAppear(_ animated: Bool) { FIRDatabase.database().reference(withPath: "data")