How to remove separator line in iOS 7? - ios

First screenshot is iOS7 that not what I want.
First screenshot is iOS6 that what I want.
Tableview's style is plain.
Tableview's separator is none.
And there is a backgroudView of that darkgray color.
I have code like below
if ([tableView respondsToSelector:#selector(setSeparatorInset:)])
{
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"icon_bg_box.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];

You need to add separate view as a seperator
First make tableViews seperator to none
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[cell addSubview:[self drawSeparationView:(indexPath.row)]];
return cell;
}
Then draw your seperator
- (UIView*)drawSeparationView:(NSInteger)itemNo {
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, self.tableView.frame.size.width, cellHeight);
UIView *upperStrip = [[UIView alloc]init];
upperStrip.backgroundColor = [UIColor colorWithWhite:0.138 alpha:1.000];
upperStrip.frame = CGRectMake(0, 0, view.frame.size.width, 2);
[view addSubview:upperStrip];
UIView *lowerStrip = [[UIView alloc]init];
lowerStrip.backgroundColor = [UIColor colorWithWhite:0.063 alpha:1.000];
lowerStrip.frame = CGRectMake(0, cellHeight-2, view.frame.size.width, 2);
[view addSubview:lowerStrip];
return view;
}
The output will be something like this

This will hide the separator
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Then add your custom separator imageView in every cell at bottom.

Try this
self.tableview.separatorColor = [UIColor clearColor];

If you want to remove the separator line of tableviewcell
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Then add separator line for custom cell
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];/// change size as you need.
separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
[cell.contentView addSubview:separatorLineView];
Credits go to iPatel Answer

Related

UITableView not displaying correctly on iPad

On the iPhone, the tableview looks fine, but in the iPad (simulator ios10), this is how it's shown:
Check image here: http://welove.pt/img/ipadtrouble.png
Any idea why its displaying differently on iPhone/iPad?
Also, what's with that white corner by the search icon? why isn't it black?
ViewDidLoad:
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorColor = [UIColor colorWithRed:58/255.0 green:58/255.0 blue:58/255.0 alpha:1.0];
_tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[self.view addSubview:_tableView];
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(54/255.0) green:(54/255.0) blue:(54/255.0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.backgroundColor = [UIColor colorWithRed:(28/255.0) green:(28/255.0) blue:(28/255.0) alpha:1];
cell.textLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == 0) {
cell.imageView.image = [[UIImage imageNamed:#"defineLocation.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UILabel *ttitle = [[UILabel alloc] initWithFrame:CGRectMake(46, 12, 320, 20)];
ttitle.font = [UIFont systemFontOfSize:17];
ttitle.textColor = [UIColor colorWithRed:(115/255.0) green:(229/255.0) blue:(69/255.0) alpha:1.0];
[ttitle setText:NSLocalizedString(#"current_location", nil)];
[cell.contentView addSubview:ttitle];
} else {
cell.textLabel.text = [[_recentSearchData objectAtIndex:indexPath.row] objectForKey:#"recentTitle"];
}
return cell;
}
Thank you for your help.
Subclassing the UITableViewCell solved the alignment issues.
Regarding that white arrow when the view is popping over on the iPad, i managed to change it's color with:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:(23/255.0) green:(23/255.0) blue:(23/255.0) alpha:1.0];
}
this viewWillAppear belongs to the UITableViewController that is shown in the popover.
Thanks for your suggestions

how to remove the line below the tableView cell in iphone

I have iphone app in which i am adding tableView and inside tableView cell i am adding the textfield but problem is that it shows line below the textfiled in tableView as shown in the image attached here is the my code.
I want to remove the line which is coming below the input filed Enter Tag Here
-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
// cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:#"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
//cell.backgroundColor = [UIColor clearColor];
}
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,1,249,28)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
tagInputField.font=[UIFont fontWithName:#"Myriad-Pro" size:8];
[tagInputField setText:#"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
[cell addSubview:tagInputField];
if(tagArray.count >0)
{
[tagInputField setBorderStyle:UITextBorderStyleNone];
}
else {
[tagInputField setBorderStyle:UITextBorderStyleRoundedRect];
}
return cell;
}
if(indexPath.section==1) {
UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(228, 8, 18, 18)];
crossButton.tag = 22; //use a tag value that is not used for any other subview
//crossButton.backgroundColor = [UIColor purpleColor];
crossButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Cross.png"]];
[cell addSubview:crossButton];
cell.textLabel.font =[UIFont fontWithName:#"Myriad-Pro" size:8];
cell.textLabel.textColor =[UIColor grayColor];
cell.backgroundColor=[UIColor whiteColor];
cell.textLabel.text =[tagArray objectAtIndex:indexPath.row];
[crossButton addTarget:self action:#selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside];
[tagInputField setFrame:CGRectMake(8,1,240,30)];
tableView.backgroundColor=[UIColor whiteColor];
[publishButton setFrame:CGRectMake(40,560,250, 50)];
[descriptionTextImageView setFrame:CGRectMake(48,450,250,90)];
return cell;
}
Update:
1) set property of tableview separatorStyle as UITableViewCellSeparatorStyleNone.
2) set property of SeparatorColor like:
[self.tableView setSeparatorColor:[UIColor clearColor]];
3) other simple way to remove seprator is add custom seprator to simple UIView of 1px height:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
separatorLineView.backgroundColor = [UIColor clearColor]; // as per your requirement set color.
[cell.contentView addSubview:separatorLineView];
4) write this delegate method of tableview:
- (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;// here remove your footer
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
// To "clear" the footer view
return [[UIView new] autorelease];
}
5) try this one:
self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,460) style:UITableViewStylePlain];
self.tblView.delegate=self;
self.tblView.dataSource=self;
[self.view addSubview:self.tblView];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
v.backgroundColor = [UIColor clearColor];
[self.tblView setTableHeaderView:v];
[self.tblView setTableFooterView:v];
[v release];
It can be from xib. Set separator to None, as below screen shot show. Hope it will help. Thanks
You should set separatorStyle property of UITableView to UITableViewCellSeparatorStyleNone.

UITableViewCell stretchable backgroundView

I have a UITableView with variable height cells. I would prefer not to have to use a background image, but rather would like to set a backgroundView with the styling that I want. Currently, I can't figure out how to dynamically change the height of my backgroundView based on the height of the cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 60)];
view.backgroundColor = [UIColor whiteColor];
view.layer.cornerRadius = 2.0;
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(0, 1);
view.layer.shadowRadius = 0.4;
view.layer.shadowOpacity = 0.2;
[cell.contentView addSubview:view];
[cell.contentView sendSubviewToBack:view];
}
ZSSLog *log = [self.items objectAtIndex:indexPath.row];
cell.textLabel.text = log.logText;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:15.0];
cell.textLabel.textColor = [UIColor grayColor];
return cell;
}
Right now the background views just overlap since they are not being resized:
Is this possible?
Instead of setting the frame of your background view you might want to do something like
UIView *view = [[UIView alloc] initWithFrame:cell.contentView.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
This answer assumes you're not using auto-layout since you're setting the frame of your background view. If you're using auto-layout you don't want to be setting the frame at all and instead setting constraints on your background view.
Normally, you'd use the backgroundView property for this. Try setting up your background view like this:
UIView *view = [[UIView alloc] initWithFrame:cell.bounds];
view.frame = UIEdgeInsetsInsetRect(view.frame, UIEdgeInsetsMake(0, 10, 0, 10));
view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//...other cell config...
cell.backgroundView = view;
But if you really want to put this view inside the contentView, you can do that like:
UIView *view = [[UIView alloc] initWithFrame:cell.contentView.bounds];
view.frame = UIEdgeInsetsInsetRect(view.frame, UIEdgeInsetsMake(0, 10, 0, 10));
view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
//...other cell config...
[cell.contentView addSubview:view];

Cell background view not filling the whole cell

I am using a separate UITableViewCell for the UITableView and when i set background View of this cell, it seems to fill the image in a box rather than the whole cell. The dimensions of both separate UITableViewCell and UITableView's row are 280x44. Here's an image of what it looks like:
Here's the code that i am writing for setting the background view of the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ...
PBDashboardSummarizedCell *cell = (PBDashboardSummarizedCell *)[tableView dequeueReusableCellWithIdentifier:#"PBDashboardSummarizedCell"];
if (!cell) {
cell = [PBDashboardSummarizedCell standardCell];
}
if(datapickup.isexpanded==YES)
{
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
av.opaque = NO;
av.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"dashboardCellEffect.png"]];
cell.backgroundView = av; //tried this
// [cell setBackgroundView:av]; //and this also... but still image is set in the box and not the whole cell
}
else{
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
cell.backgroundView = av;
}
return cell;
}
Try this code. it worked for me.
UIImageView * ac= [[UIImageView alloc] init];
ac.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"image.png"]];
cell.backgroundView =ac;
cell.backgroundColor = [UIColor clearColor];
try this?
UIImage *backgroundImage = [UIImage imageNamed:#"dashboardCellEffect.png"];
UIView *backgroundCellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
// redraw the image to fit cell's size
UIGraphicsBeginImageContextWithOptions(backgroundCellView.frame.size, NO, 0.f);
[backgroundImage drawInRect:CGRectMake(0.f, 0.f, backgroundCellView.frame.size.width, backgroundCellView.frame.size.height)];
UIImage *refinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[backgroundCellView setBackgroundColor:[UIColor colorWithPatternImage:refinedImage]];
cell.backgroundView = backgroundCellView;
you are using imageview so it shows color in only imageview instead of whole cell
you can try below method
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(datapickup.isexpanded==YES)
{
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"dashboardCellEffect.png"]];
}
else {
cell.backgroundColor = [UIColor clearColor];
}
}
tyr above code your problem will solve.

UITableView put text on top of image

I have a UITableView that has an image and text on each cell, however they are put side by side. What I'm trying to do is put the text label over the top of the image. Is it possible?
Take custom UITableViewCell,where take UIView at every cell and make your image as the background color of the UIView then take a UILabel at the top of the UIView.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:#"Arial" size:15.0];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"pl_arows.png"]];
cell.accessoryView = imageView;
cellView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,290, 70)] autorelease]; //important do not changer the position
cellView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"order_description_bg.png"]];
cellView.tag =10;
[cell.contentView addSubview:cellView];
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 39, 36)];
imgView.image = [UIImage imageNamed:#"image_category.png"];
imgView.layer.borderColor = [UIColor blackColor].CGColor;
imgView.tag = 5;
[cellView addSubview:imgView];
//Status label
CGRect statusRectText = CGRectMake(52, 0, 50, 18);
UILabel *statusLabelText = [[[UILabel alloc] initWithFrame:statusRectText] autorelease];
statusLabelText.textAlignment = UITextAlignmentRight;
statusLabelText.backgroundColor = [UIColor clearColor];
statusLabelText.tag = 101;
[imgView addSubview:statusLabelText];
}
You will have to define a custom UITableViewCell in which you can place any standard UI objects, including a UILabel on top of your UIImage.

Resources