I am doing a slide menu using a UITableView and I have 2 options on the menu and I want to put a button at the bottom like in this image:
I try to do that add a tableFooterView like that.
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 500, 320, 70)];
footerView.backgroundColor = [UIColor blackColor];
self.tableView.tableFooterView = footerView;
However, the view appears just after the second cell, but I want it at the bottom.
Thanks for help.
No you shouldn't add any empty cells, that's just hacky. If you really need the button to be at the bottom, you should use layoutSubviews to control the frame of the tableView and the footerView.
- (void)layoutSubviews
{
[super layoutSubviews];
self.tableView.frame = // top 80% of the screen
self.footerView.frame = // bottom 20% of the screen
}
You should know that every UITableViewCell has its height and footer is part of a UITableView and will appear at the bottom of a UITableView. If you want to make your UITableView look like what that image shows, you should make sure that your cells are high enough to make sure that your UITableView are high enough so that footer will appear at the bottom of UITableView
My suggestion is to add extra "empty" cell(I mean a cell with no content but has a height).
Add a Container View with View Controller from storyboard. You can use autoresizing to set the buttons on right place.
Related
I'm using Masonry to set the constraints of the subviews.
The view controller is simple.
in viewDidLoad
-(void)viewDidLoad
{
[self.view addSubview: self.tableView];
self.view.backgroundColor = [UIColor whiteColor];
[self.tableView addSubview: self.botBtn];
[self.botBtn makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.tableView.bottom).with.offset(-20);
make.centerX.equalTo(self.tableView);
}];
}
The frame for the table view is CGRectMake(0,0,screen_width,screen_height),
but the button is outside of the screen and just on the top of the tableview.
I set the tableview frame in it's init method.
The button stays in the mid of the view horizontally so the autolayout seems work, but why it is positioned on the top of the tableview instead of staying on the bottom.
Firstly well done for using Masonry :D.
To your question, I don't think you're adding the button in the right way, I'm guessing you want to add a button to bottom of the tableview, so when you scroll to the bottom of the tableview you will see your button? If so, just create a UIView with a button and set the tableview's footer view, i.e. [self.tableView setTableFooterView:newView]; as described in this question, Adding a button at the bottom of a table view
Let me know if this is not what you're actually looking for, good luck.
I have a table,with settings that cell height is 40px.
If my cells have a label, image or any other component starting at 41px it will still appear in the table overlaping the cells underneath.
How to resolve this? I do not want the rest of the cell to be shown, just the height that is
set in my table settings.
Thank you.
Please add up these methods and try,
-(float)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)] autorelease];
view.backgroundColor = [UIColor clearColor];
return view;
}
Using this will be considered as end of data from data source. And rest cells will not be displayed.
[Will solve this issue - If my cells have a label, image or any other component starting at 41px it will still appear in the table overlaping the cells underneath]
You want to hide the content of cell that is below the 40px level? Add UIView to cell.contentView with white colour above the content of cell with 41px origin.y
A little late, but just in case anyone else is running into this issue. If using IB, ensure "Clip Subviews" is checked on your table view cell. And this:
self.contentView.clipsToBounds = YES;
should do the same thing.
You didn't solve this problem because the point is not the UITableViewCell. It's Aspect Fill Mode of UIImageView.
Select the UIImageView in the SB, check this on!
My UITableView has a subview with a fixed position. But when I scroll, the scrollbar is hidden by the subview. How can I avoid this?
## EDIT ##
self.menuViewRelative = [[UIView alloc] init];
self.menuViewRelative.backgroundColor = [UIColor whiteColor];
self.menuViewRelative.opaque = YES;
self.menuViewRelative.frame = CGRectMake(0.0, -1.0, 320.0, 50.0);
[self.view insertSubview:self.menuViewRelative atIndex:11];
This subview is now above 10 other subviews and exactly 1 layer under the scrollView (so it displays the scroll indicator perfectly).
Adding as an answer as per Jesse Rusak's comment.
Set scrollIndicatorInsets for the table view in such a way that the scroller will be moved in a place where subview wont overlap.
For eg:-
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 7.0);
Are you using addSubview: for this? That will make it the top-most subview, which will cover the scroll bars. If you instead use insertSubview:atIndex: and ensure it's just above the other content in your table view, it will be below the scroll bars.
You might need to override layoutSubviews of the UITableView (like I describe in this related question) and look through the contents of the table view in order to keep your floating view just above the table view cells.
Hi i want to add a line in my UITableView just like the reminder apps red line. I tried adding it to my custom cell but then it only display in the cell which are used and not in all cell. I want a red image like below
Thanks in advance
You could use a UIView that has the size of the red stripe and place it over your UITableView where you want the red line to appear. Set it's backgroundColor to the color of the red line and make sure that userInteractionEnabled is set to NO to avoid interfering with the scolling of the UITableView.
Try To add UIView on tableView and set it`s Background Color with pattern Image whatever you want,then add such view on tableview. like below.
lineView = [[UIView alloc] initWithFrame:CGRectMake(100, 0, 1,
tblView.frame.size.height)];
[lineView setBackgroundColor:[UIColor blackColor]]; //Change as per your req.
lineView.userInteractionEnabled = NO;
[tblView addSubview:lineView];
But you face problem with this when you scroll up then at vertical bounce you have to manage height of this UIView. So you can implement this by ScrollViewDidScroll Delegate method, This method call cause UITableView is extends from UIScrollView.
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
lineView.frame = CGRectMake(100, 0, 1, tblView.frame.size.height+scrollView.contentOffset.y);
}
I want to display a double bordered like following image...
The border has a dark color (magenta) and a light color (white) (not the actual colors).
I have created a custom .xib file and a custom class extending UITableViewCell for my table view cells.
self.tableView.separatorColor = [UIColor whiteColor];
Then in the custom table view class, I did this...
- (void)awakeFromNib
{
[super awakeFromNib];
UIView *cellBottom = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height, self.bounds.size.width, 1.0f)];
cellBottom.backgroundColor = [UIColor magentaColor]; //
[self addSubview:cellBottomView];
// ... other code
}
I got the following result... there seems to be some gap between backgroundColor and separatorColor.
Why is this happening? The height of UIView has been set to 1 and is positioned at the bottom of UIView as well.
If there is some better solution to this could somebody throw some light on that?
Michal Zygar is partially correct.
Make sure your -(NSInteger)tableView:(UITableView*) heightForRowAtIndexPath:(NSIndexPath*) is correctly set to the height of the view. It doesn't automatically do that for you.
The other tip I would suggest as I do it myself, is to NOT use separators. Set your separator to none, and then add in two 1px-heigh views at the top and bottom of the cell in the XIB file.
Make sure to set the autosizing for the bottom two to stick only to the bottom edge, just in case you want to change the cell's height!