Is there a way to define a space for a particular cell? I am able to set spacing for all cells with the following property in gridview:
_grid.columnSpacing
I display five views on the screen. I need to set more spacing only for the second and the fourth views that are displayed on the screen.
Hi,
ColumnSpacing is uniform. So it can only be applied to all or none.
If you want additional space on a particular column, your best option is a custom cell, and insetting your content.
-SteveZ
Hi Steve, insetting you mean updating it's frame( origin.x ) during the transition?
Hey,
Basically, just laying out the content in the cell, so that it doesn't use the full space.
For example. if i was just displaying a label in a custom cell, i might do something like this.
-(void)setupSize:(CGSize)size{ // Without Inset myLabel.frame = CGrectMake(0, 0, size.width, size.height); // With Inset CGFloat padding = 10; myLabel.frame = CGRectMake(padding, 0, size.width - padding*2, size.height); }
What i'm doing is no longer using the full width of the column, but instead leaving a gap in front of and after the label.
This assumes of course that i'm not setting a background color on the cell.
I am using carousel and each view is a circle. The one at the center is the biggest circle view. I display 5 views on the screen.
The second view should close to the left side and the fourth view should close to the right side of the screen. I cannot set frame in cellLocationInViewportChanged method because of snapping animation.
------------- Visible Screen --------------View1 View2 View3 View4 View5
Also I have a boolean variable telling me that whether or not the view is next to the center cell. With the help of this variable I don't have to update all 5 views on the visible screen. It let's me to focus only the second and the fourth views. I need to do like:
if (isBehindCell) {CGPoint position = self.layer.position;CGFloat maxOffset = self.layer.position.x - 10;CGFloat minOffset = self.layer.position.x;position.x = ((maxOffset - minOffset) * percent) + minOffset; }
I need like:
The code above didn't work well. It breaks down the position of the views. Is it technically possible to set the carousel views x positions without breaking the transition or seeing snapping? Thank you Steve.
Sorry, I didn't realize in this situation you were referring to column spacing in regards to using carousel behavior.
Thats much more complicated, you essentially need to write a different algorithm for calculating your cell positions.
Can you send me the code or sample of what you're currently doing? I'll then see if i can modify it to do what you're looking for.
Thank you so much Steve for your great technical support!! I really appreciate it.
No problem.
You can actually control that with the existing sample.
There is a variable called spacing. This is the spacing between cells.
You can play around with that variable until you find something that works for you.
CGFloat spacing = scaledItemSize/2; // Try making it something like scaledItemSize/2.75 to decrease the spacing
Let me know how that works for you.
CGFloat spacing = scaledItemSize/2.1;
gives me this screenshot. I only need to adjust the spacing at the left and right side of the centre circle not all spacing in between the circles.
Thank you Steve. I really appreciate your technical support! The following setting is really nice. With the help of this parameter I am able to adjust the center view's size.
CGFloat additionalMulitper = .5f; // Increase this to make the center circle even bigger
I still need to slightly bring the circles under the centre one. Is there a way for to do this with another parameter? like distancefromcenter = .2f; will bring the circles close to the center circle. The sizes of the circles are ok except the space next to the centre circle.
Sure.
You can't just increase the Max scale, b/c that will affect all the cells relative size.
Instead, you need a little big of additional logic.
I've adjusted the sample. There is a new local variable:
To make the center item bigger, just increase this multiplier and you should get your desired results.
Hope this helps,