Custom Bottom Border not appearing on iPad - ios

I added a bottom border to a uitableviewcell programmatically (iPhone - Create custom UITableViewCell top and bottom borders):
UIView *bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.bounds.size.height, self.view.bounds.size.width, 1)];
bottomLineView.backgroundColor = [UIColor grayColor];
[cell.contentView addSubview:bottomLineView];
It's not displaying on an ipad unless you highlight it. All the other cells below and above it have the background color set to clear.. It displays fine on the iPhone

Move the line one pixel up. Right now it's outside of the frame, getting overlayed by the next cell.
UIView *bottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0,
cell.bounds.size.height - 1,
self.view.bounds.size.width,
1)];

Related

UITableViewCell separator insets don't work when table.width is much greater than view.width

UITableViewCell separator insets don't work when table.width is much greater than view.width on iOS 10, I haven't try it on the device which iOS version is less then iOS 10.
code is here on gist
You can add separator in your UITableView using the below code
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 3)];/// change size as you need.
separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
[cell.contentView addSubview:separatorLineView];
and remove the default separator of your UITableView. Hope it helps.
_tableView.cellLayoutMarginsFollowReadableWidth = NO;
it works above.
refer to
iOS 9 UITableView separators insets (significant left margin)
Xcode 7 iOS 9 UITableViewCell Separator Inset issue
There are two ways in which you can solve this problem.
First one you can add a separator line view in cell content view.
UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableview.frame.size.width, 3)];
line.backgroundColor = [UIColor whiteColor];
[cell.contentView addSubview:line];
The second one is apple provided one and pretty easy also just add this line of code where u declare your tableview
yourTableView.cellLayoutMarginsFollowReadableWidth = NO;

Xcode delete a line on top of an image

I have an image in a UIView.
On top of it I have drawn a blue, horizontal line with:
UIView *lineViewHorizon = [[UIView alloc] initWithFrame:CGRectMake(0, pageTopMargin+inthorizon, self.view.bounds.size.width, 2)];
lineViewHorizon.backgroundColor = [UIColor blueColor];
[self.view addSubview:lineViewHorizon];
How do I remove this line so the picture appears without the line in front of it.
Clearly using clearColor does nothing :-)
Do I need to delete the layer and if so how?
[lineViewHorizon removeFromSuperview]

Add Margin to a custom UI Table Cell

I'm fairly new to the native app dev world and predominately a Front-End Dev/designer - I have built a IOS7 app in Xcode 5 - which contains a UITable with several custom cells. I would like to add margin of approx 8px to each of the cells (to look like the image below) - and change the colour of the link arrow which appears via a push segue - but have no idea how to do either despite a good web search / book read - theres doesnt seem to be the relevant options on the storyboard.
Can anyone advice if possible?
the code goes like this method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
for add margin of each cell (this code add margin only to top of each cell):
UIView *separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 8)];
separatorLineView.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:separatorLineView];
and for color of arrow you have to create an image and insert it with this code:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 7, 11)];
[label setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"yourimage.png"]]];
cell.accessoryView = label;
You can include a margin to the cell by resizing the table itself. Instead of the standard 320 pixels width, change the width of the table to 312. That will give you an overall margin without having to meddle with the internals of the table view.
CGFloat margin = 8;
self.tableView.frame = CGRectMake(0, 0, self.view.frame.width-margin, self.view.frame.height);
In order to change the color of the arrow, you have to change what's called the accessoryView of the UITableViewCell. It can be any UIView.
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"coloredArrow.png"]];

Remove rounded corners UITableViewCell

I've been trying to do this for a while now. I just want to remove the rounded corners you can see on this picture :
Does anyone know how to do it ?
[EDIT 1 : CELL BUILDING]
I am subclassing UITableViewCell to make my own layout. And then I'm adding a background to these cells like below :
UIImageView* imageView = [ [ UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 44.0)];
imageView.image = cellBackground;
cell.backgroundView = imageView;
I you need to edit the backgroundview of the corresponding cell. E.g.
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
bg.backgroundColor = [UIColor whiteColor]; // or any color
cell.backgroundView = bg;
[bg release];
The corners aren't rounded by default, just so you know.
Do you have a background image for the cell that makes the corners
seem rounded (most likely)?
Is each cell actually a section of the
tableview and there is no space between them?
Are you testing on a
jailbroken iPhone and you have some winterboard theme installed that
changes the style of tableviews?

Vertical space between UITableViewCells after setting the backgroundView on a cell

I am implementing UITableViewCells that have a custom background and expands when tapped.
I am setting a custom view as my UITableViewCells backgroundView: (in RowForIndexPath)
if (cell == nil) {
CGRect f = CGRectMake(0.0f, 0.0f, 300.0f, 50.0f);
cell = [[UITableViewCell alloc] initWithFrame:f reuseIdentifier:cellIdentifier];
UIView *back = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 300.0f, 50.0f)];
back.layer.cornerRadius = 8.0f;
[back setBackgroundColor:[UIColor blackColor]];
This works fine, by setting the backgroundView instead of the contentView, my backgroundView scales to accommodate the new size of the cell after it expands (changing the height in heightForRowAtIndexPath after a tap).
My problem is now that I would like a few pixels vertical space between my cells. Using the above approach will make the rounded black cells be displayed "back to back".
Is there a way to add the vertical space between the cells or is there a completely different approach I can take to obtain the desired look of my cells?
Thanks in advance.
In order to display a space between cells and avoid the "back to back" issue that you are having you can add a UIView with the the following frame CGRectMake(0, 0, 320, 1) and the background set to a light gray for the standard cell separator or if you just want some padding you can make the background clear.
Personally I like to use interface builder but you can of course do this programmatically.
UIView *cellSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320 ,1)];
[cellSeparator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleWidth];
[cellSeparator setContentMode:UIViewContentModeTopLeft];
[cellSeparator setBackgroundColor:[UIColor lightGrayColor]];
[cell addSubview:cellSeparator];
[cellSeparator release];
The reason I set the cellSeparator at the top of the cell is because the effect is really for the cells that fall in between the first and last rows. Also it is important to set the autoresizingMask and the contentMode to make sure the cell separator adjusts properly when you make size changes to the UITableViewCell. If you have any elements in the cell that start at x=0 y=0 of you will need to move them down the height of the cell separator plus perhaps some additional pixels for padding so that the separator doesn't run through any elements with in the cell.

Resources