I want to make my cells separated. Is there a way I can increase the space between tableview cells?
As you can see in this photo, I want to make the cells appear further away from each other. Is there a way I can achieve this?
If you are using a storyboard for UI and a using custom cell in your tableview, you can achieve your goal by keeping the custom cell's frame bigger than Content View's View.
So, if cell > Content View's frame = 0, 0, 375, 100
Please make, cell > Content View > View's frame = 15, 5, 345, 90
You can fix the spacing between your cells by making the cell Fram bigger than the content view.
You can do it by the storyboard. Or by using the delegate method estimatedHieghtForRowAt and height for rowAt.
Related
I have complex view that contains Image slider(collectionView),List of offers(tableView) and List of Services (TableView), The main Content View should be scrollable and all subviews should not be scrollable.
I tried to make the parent view UIScrollView but i got a problem that when the first tableview items exceeds the screen limit its not showing the exceeded elements.
I tried also to force full tableview height but i had a problem with scrolling
self.tableView.frame.size = CGSize(width: self.tableView.contentSize.width,
height: self.tableView.contentSize.height)
Is there a way to force showing all the tableview elements ,or should i use another type than UIScrollView?
Here is an image for what i want to display
For this you need to disable your UITableview scroll like:
tableView.scrollEnabled = false
then all you need to get count of tableview element multiply it by the height of your tableview cell and set that height to tableview like:
tableViewHeight.constant = count * z
Where z is height of tableview cell.
All set now.
I'm using a table and image in my program.
I placed the image on top and table just below that.
Now I need to keep the Image static and On scrolling I want the table to go above the image according to the scroll height.
Use the contentInset of your UITableView to adjust the initial offset of the content. Make sure your tableView is front of your UIImageView.
[self.tableView setContentInset:UIEdgeInsetsMake(viewHeight, 0, 0, 0)];
contentInset will only adjust the initial content position, so when scrolling, the whole frame of your UITableView is used.
Update: UIView is UIImageView in your case
You can use it by Placing both the UIImageView and UITableView in UIScrollView
And set UIScrollView contentSize() according to need like
1.) scrollView.scontentSize = CGSizeMake(scrollView.frame.size.width, imageView.frame.size.height + tableView.frame.size.height + 10);
2.) Set UITableView scrolling to NO
This would help you.ThankYou
I'd like to have a UITableView which is full screen. But the content of the UITableView should have a padding on the left and right.
So I tried to set ContentInset. But now the cells are as wide as the UITableView and the UITableView scrolls horizontally.
Is there a way to say that the UITableView content's width should become narrowed by the horizontal content insets? Or do I have to add the padding to all cells and header/footer views?
I don't want to narrow the table view itself, because the scroll indicator should stay at the right side of the screen and not in the middle.
The here (How to set the width of a cell in a UITableView in grouped style) suggested solution seems to be not as generic as i'd love to, beacuse the cells and header and footer views have to know about the padding (at least 3 places to maintain instead of one)
I don't want to narrow the table view itself, because the scroll
indicator should stay at the right side of the screen and not in the
middle.
This makes you happy?
_tableView.clipsToBounds = NO;
_tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, -30.f);
If you don't like clipsToBounds = NO effects, you can embed the tableView in container view which is clipsToBounds = YES.
Set the layout margins of the table view. For this to work make sure your constraints in the cells are set relative to the superview margin.
tableView.layoutMargins = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 40)
I have a grouped tableView in my iPad-app, and I've been trying to set cell.imageView.center = cell.center to center the image instead of putting it to the leftmost position. This is apparently not possible without a subclass of the UITableviewCell(If someone could explain why, that'd also be appreciated.. For now I just assume they are 'private' variables as a Java-developer would call them).
So, I created a custom tableViewCell, but I only want to use this cell in ONE of the rows in this tableView. So in cellForRowAtIndexPath I basically write
cell = [[UITableViewCell alloc]initWith//blahblah
if(indexPath.row == 0)
cell = [[CustomCell alloc]initWith//blahblah
This is of course not exactly what I'm writing, but that's the idea of it.
Now, when I do this, it works, but the first cell in this GROUPED tableView turns out wider than the rest of them without me doing anything in the custom cell. The customCell class hasn't been altered yet. It still has rounded corners though, so it seems it knows it's a grouped tableView.
Also, I've been struggling with programmatically getting the size of a cell, in cellForRowAtIndexPath, I've tried logging out cell.frame.size.width and cell.contentView.frame.size.width, both of them returning 320, when I know they are a lot wider.. Like, all the rows are about 400 wide, and the first cell is 420 or something. It still writes out 320 for all the cells..
This code will not work for a couple of reasons:
cell.imageView.center = cell.center;
Firstly, the center is relative to its superview. I believe the cells superview is the tableView. The imageView's superview will be the content view of the cell. Therefore the coordinate systems are different so the centens will be offset. E.g. the 3rd cell down will have a center of 0.5 widths + 3.5 heights. You should be able to ge around this issue by doing:
cell.imageView.center = CGPointMake( width / 2 , height / 2 );
The second issue is related to how the table view works. The table view manages its cells view's. The width of a cell is defined by the table view's width and the height is defined by the table view's row height property. This means the cell itself has no control over its size.
You can however size its subviews, but you must do this after the cells size has been set (otherwise you can get strange results). You can do this in layout subviews (of the custom UITableViewCell class). See this answer.
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = ....
}
When layoutSubviews is called the cells frame has been set, so do your view logging here instead of cellForRowAtIndexpath.
As for the GROUPED style. Im not sure if this is designed to work with custom views. I suspect it sets the size of its cells to its own width minus a 20 pixel margin on each size, then applies a mask to the top and bottom cells in a section to get the rounded effect. If you are using custom view try to stick with a standard table view style.
In my application, I rotated the table view for 90 degrees i.e., the table view is now horizontal table view. After rotation I tried to increase its scroll size as I was unable to view the last row but I couldn't increase it. As table view is sub class of UIScroll view, I tried to change it in Interface Builder but nothing solved my problem. Please tell me how to increase this table view scroll view width to view all the contents.
rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
tableView.transform = rotateTable;
[tableView setFrame:CGRectMake(40, 333, self.view.frame.size.width , 37)];
In IB,Size Inspector: Scroll View Size: Scroller Insets : Right : 500 (I changed the Right attribute to increase the width)
You don't need to manage it. Tableview does it itself. Your problem is frame of tableview. Your tableview is crossing bounds of it's superview(view in which tableview is added). Check tableview's frame. Make sure it will not exceed bounds of superview.