iPhone: Removing rounded corners from table view cell - iphone

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.

Related

how to change the background of table view , quickdialog box

I am following the tutorial about a quick dialog box to create a form as below
Now, I would like to change the background of this form. Does anybody know how to achieve this, please advice me on this.
Thanks
Try this, if you want to show an image as a background:
tableView.backgroundColor = [UIColor colorWithPattern:#"your_image_here"];
or
tableView.backgroundColor = [UIColor colorWithRed:128 green:128 blue:128 alpha:1.0];
If this does not work, you can set the backgroundView property of the table view:
tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"your_image_here"]]] autorelease];
Use the backgroundView property of the UITableView.
If you want to use an image, just create a UIImageView and set backgroundView to it.
UIImage *myImage = [UIImage imageNamed:#"foo.png"];
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:myImage];
You may also use the contentMode to adjust how the image fits in the view.
self.tableView.backgroundView.contentMode = UIViewContentModeScaleAspectFill;
You could try some of the properties that UITableView either inherits or declares:
#property(nonatomic, readwrite, retain) UIView *backgroundView
#property(nonatomic, copy) UIColor *backgroundColor
The first is probably what you are going to want. It is declared by UITableView. The second is inherited from UIView.
If you're setting a background colour try this...
tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor redColor]; //replace with your colour
But if you want a pattern image don't use that method... Do this..
tableView.backgroundColor = [UIColor clearColor];
UIView *v = [[UIView alloc] init]; //needs memory Managment (arc example)
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"pattern.png"]];
tableView.backgroundView = v;
This is because if the UITableView is group styled the and you have a patterned background image as the tableviews backgroundColor then it's applied to the edges of the cells too but as they're separate views the pattern becomes incorrect.
Hope it helps.
Try to set the background color of the table view; it may require that you change the table view style from grouped to plain.

UIView Background Image Transparency Problem

I added a subview with an PNG image that should display with transparency, but I am getting all black where the transparency should be.
The code is:
- (void)viewDidLoad
{
[super viewDidLoad];
toolbar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BannerBackground.png"]];
logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Logo.png"]];
[self.view addSubview:logoImage];
}
This is code for a iPad, iOS version 4.3. I have the same problem with both the simulator and the iPad.
Since this is the last view added, I expect it to have a z index higher than all of the other views, so the other views should show through the transparent areas. This is not working.
I noticed this behaves differently on iOS 4.3.x than 5.0.x. In 4.3.x I had to set opaque to YES, then set the background image, then set it back to NO.
Set your view's property opaque to no. like this [view setOpaque:NO];
Failing setOpaque:NO... check to see if your image is correctly exported and not corrupted etc.. that happened to me once
Create a UIImageView with transparent backgroundColor and your logo as its image, and add that:
UIImageView *logoView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:#"Logo.png"]];
logoView.backgroundColor = [UIColor clearColor];
[self.view addSubview:logoView];
This should work.
#import <QuartzCore/QuartzCore.h>
logoImage = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 56)];
logoImage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Logo.png"]];
[logoImage.layer setOpaque:NO];
logoImage.opaque = NO;
[self.view addSubview:logoImage];
Old question, but: any chance that your transparency is, for instance, black and not actually transparent? Not that I just did that or anything.
(When drawing the toolbar icon, iOS fills in any pixels, including black ones, with white. Make sure there's actually nothing where you expect your transparent area to be.)

How to set UITableView background to image?

I've noticed that a number of apps have a custom background image for UITableView (or have set the background to a color.)
I can't find any API in the UITableView class to affect this, and my attempts in interface builder have failed (trying to set the color of the UIView)
Any suggestions? I've seen a third party app with pictures, so I know it can be done.
I just ran into the same question myself, but I found a way to do it that TomSwift touched on. As he mentioned, UITableView has a backgroundView property that is intended to do just what you're looking for. If you want to set the background color, you should instead use the backgroundColor property, as others have said. So:
// Set an image as the background of a UITableView called 'tableView'
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"MyImage.png"]];
[tableView setBackgroundView:bg];
or:
// Set a solid color as the background of a UITableView called 'tableView'
// In this case I chose red
[tableView setBackgroundColor:[UIColor redColor]];
add this line in you code where you want to set background color for your image
[YourView(or imageView) setbackgroundColor:[UIColor
groupTableViewBackgroundColor]];
Thanks
UIImageView *image = [[UIImageView alloc] initWithImage:
[UIImage imagenamed:#"no_image.png"]];
[self.view addSubview:image];
UITableView *tableview = [[UITableView alloc] init];
[image addSubview:tableview];
tableview.backgroundcolor = [UIColor clearColor];
try this. it works for me.
CALayer *background = [CALayer layer];
background.zPosition = -1;
background.frame = self.view.frame;
background.contents = [[UIImage imageNamed:#"background.jpg"] CGImage];
[tableView.layer addSublayer:background];
you need to add an image view and set the table background color to clear color see this link for tutorial
Set the backgroundView property of the tableView. You can set it to a view where you have set a custom backgroundColor, or you can set it to a UIImageView where you've set an image.
alternative solution of GhostRider
No coding
Make UiImageView by the interface builder,
put your image in resources.
set it in UIImageView Image property by the use of Inspector.
select table view and set it background color to clear(for this make opacity to 0 by using attribute inspector).
This is how I did it. Probably not the best way, but works well enough.
UIImage *bg = [UIImage imageNamed:#"bg"];
[bg drawInRect:self.view.window.frame];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.window.frame];
bgView.image = bg;
activityTable.backgroundView = bgView; //activityTable = UITableView

Removing cell borders from a section of grouped-style UITableView

I have a UITableViewController initialized with the grouped style and having multiple sections. For one of these sections, I'd like its constituent cells to be completely transparent and have no border. I plan to assign a custom view for every row in this section, but having that custom view surrounded by the grouped table cell looks bad :(
The following makes the background color of a cell black instead of transparent... And I still don't know how to get rid of the border.
cell.backgroundColor = [UIColor clearColor];
Any pointers? Thanks!
NOTE: This doesn't appear to be working in iOS7 and above. For iOS7 try this answer.
For iOS6 and below, to remove the grouped background from a cell in a grouped table view cell:
This didn't work
cell.backgroundView = nil; // Did Not Work
This did
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
If you have moved to ARC (I've heard this works, but haven't tested it)
cell.backgroundView = [UIView new];
You have to actually set
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
to remove the border of cells.
The following hack works in iOS 7 – for now. :)
Subclass UITableViewCell, and use this cell for the section that shouldn't have separators.
Override the addSubview method in your cell subclass:
-(void)addSubview:(UIView *)view
{
// The separator has a height of 0.5pt on a retina display and 1pt on non-retina.
// Prevent subviews with this height from being added.
if (CGRectGetHeight(view.frame)*[UIScreen mainScreen].scale == 1)
{
return;
}
[super addSubview:view];
}
This is what worked for with having a Grouped style table
[tableView setSeparatorColor:[UIColor clearColor]];
This code worked for me :)
[self.tableView setSeparatorColor:[UIColor clearColor]];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Set the backgroundView of the cell to nil. For a grouped table, the cell image is part of that view.
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
Try using tableView.separatorColor = [UIColor clearColor];
And, don't use tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
I tested with both, if style is none, making the section borders invisible is not working, but instead just change its color, and section border will appear to be none.
iOS seems to be differentiating making an object none and making an object transparent
cell.backgroundView = [UIView new];
Works like a charm! Tested! iOS6
As of iOS 8, setting the separator attribute to none works as well.
Setting a content view also gets rid of the border. Set your custom view to cell.contentView.
The easiest way to remove cell borders from a section of grouped-style UITableView:
[tableViewOutlet setBackgroundView:nil];
in the viewDidLoad method.
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
cell.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:imageView];
If you have a custom UITableCellView then you can add the following method to your view to remove the background view.
- (void)setBackgroundView:(UIView *)backgroundView
{
// We don't want background views for this cell.
[super setBackgroundView:nil];
}
I just thought I would convert my comment to #Intentss into an answer, because it maybe useful for those, using his solution.
Using iOS6.1 with a grouped UITabelView, using ARC:
[tableView setSeparatorColor:[UIColor clearColor]];
Does not work
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
Does work

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..