Adding separator in UICollectionViewCell like one in UITableViewCell - iphone

I am developing an app in which I need " a separator line " after each row of UICollectionViewCell...(like in UITableView after each row).
Anyone having idea how to get this?

Create a UIView with a black background that is 1 pixel high and 320 pixels wide?
For Example
For Horizontal Line
UIView *horizontalLine = [[UIView alloc]initWithFrame:CGRectMake(x cordinate,y cordinate,1,linelenth)];
horizontalLine.backgroundColor = [UIColor blackColor];
[self.view addSubview:horizontalLine];
[horizontalLine release];
For Vertical Line
UIView *verticalLine = [[UIView alloc]initWithFrame:CGRectMake(x cordinate,y cordinate,linelenth,1)];
verticalLine.backgroundColor = [UIColor blackColor];
[self.view addSubview:verticalLine];
[verticalLine release];

Related

ios 7 - uitableviewCell Separator line

I need to display separator line in iOS 7 same like iOS 6 (as my image 2). I am using below code in CellForRowAtIndexPath:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor colorWithRed:229/255.0 green:229/255.0 blue:229/255.0 alpha:1.0];
[cell.contentView addSubview:separatorLineView];
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"cell_highlighted.png"]];
cell.selectedBackgroundView = customColorView;
cell.backgroundColor=[UIColor clearColor];
//Separation style for iOS7
if ([tableView respondsToSelector:#selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
return cell;
I am getting output as below image:
But my output should like below image for both IOS 6 and 7:
Can anyone please help me how to achieve this? Thanks..
contentView doesn't always have the same size as the cell itself, add separator view on top of the cell view above the content view:
separatorLineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell insertSubview:separatorLineView aboveSubview:cell.contentView];
UITableView has a property separatorInset. Use that to set the insets of the table view separators to zero to let them span the full width of the screen.
[tableView setSeparatorInset:UIEdgeInsetsZero];
OR
You can set separator inset property in xib also. Change it to custom. And make both left and right values to zero.

UIScrollView Inside UITableViewCell

I'm trying to add a UIScrollView inside my TableViewCell. It appears to be going well, however when the label comes in from the right as I'm scrolling, it comes in above the cell, but as the text moves to the left edge of the label, it disappears behind the label like I want it to.
Any suggestions?
UIScrollView *previewScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 80.0)];
previewScrollView.backgroundColor = [UIColor clearColor];
[previewScrollView setContentSize:CGSizeMake(500, 60.0)];
previewScrollView.showsHorizontalScrollIndicator = YES;
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 3.0, 500.0, 20.0)];
headerLabel.font = [UIFont boldSystemFontOfSize:14.0];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.text = #"My long text string that I hope work out ok";
[previewScrollView addSubview:headerLabel];
[[cell contentView] addSubview:previewScrollView];
//[cell addSubview:previewScrollView];
[previewScrollView release];
from the right as I'm scrolling, it comes in above the cell
Above the cell as in y or z axis?
If it is above in the y axis, you could try setting clipsToBounds on the scroll view. That makes it so subviews are only drawn within the area of their superview.
If it is above in the z axis, where something in front should be behind, try using:
[[cell contentView] insertSubview:previewScrollView atIndex:0];
inserting at index 0 ensures a view is behind all other subviews in the superview.

UITableView cell takes pattern color of UITableView's background image

I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:
The background image shell look like this:
*pay attention to white circles that disappear under the cells!
My code is as follws:
in viewDidLoad i set the background image of table view:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"general_bg.png"]];
For each cell i remove any background color like this:
UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bckView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bckView;
cell.backgoundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)];
textLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textLabel];
line separators are custom images added to cells.
Instead of setting the BackgroundColor attribute of the tableview, try setting the backgroundview:
UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds];
background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
self.tableView.backgroundView = background;
This should fix the issue of the cell's taking on the same image as the background.
self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
maybe this is what you're looking for

How to Draw a line in UITableViewCell

I need to draw a line in UITableviewcell.
There is any possible way to do this one?
If anybody having any idea about to draw a line in UITableview cell please reply me.
Thanks.
If the line is horizontal or vertical you could add a black UIView. Like this.
UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0, 25, cell.contentView.bounds.size.width, 1)] autorelease];
lineView.backgroundColor = [UIColor blackColor];
lineView.autoresizingMask = 0x3f;
[cell.contentView addSubview:lineView];
The one above is for one horizontal line. The following code works if you need a vertical line in the middle of the cell
UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake((cell.contentView.bounds.size.width/2), 0, 1, cell.contentView.bounds.size.height)] autorelease];
The easiest way is to take the image of the line and put it in UIImageView and add the image view to cell's content view... don't go all the way to actually 'drawing' it.. it'll be an overkill..

iPhone: Removing rounded corners from table view cell

i have a table view in my application which shows rounded corners by default.
Is there any way to remove the rounded corners.
I have #import <QuartzCore/QuartzCore.h> in place and included the frame work as well.
eve the following code does not work
self.clipsToBounds = NO;
self.table.layer.cornerRadius = 0.0;
can any one suggest a solution?
Thanks in advance
For a UITableViewStyleGrouped cell, you'll need to change the backgroundView on your cell.
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)];
bg.backgroundColor = [UIColor whiteColor];
cell.backgroundView = bg;
[bg release]; // if you're not using ARC
Are you using UITableViewStyleGrouped on your table view? If so change the style to UITableViewStylePlain and the cells will be rectangulars without rounded corners.