I created my UITableViewCellStyleDefault styled cell and set its background image:
cell.backgroundView = imgView;
and it works but the background of the text in the cell is still white.So it hides partially the backgroundView.
I have tried:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.opaque = NO;
but none of them worked.
Also the image used for backgroundView has transparent parts but in the cell the are not.
I wonder what I am missing.
Thanks in advance.
Refer to this: Changing UITableViewCell textLabel background color to clear
Related
I have a grouped tableview where I have one row in each section. I am setting the backgroundview of the cell to my custom image and I wish the row is rendered this way:
But it renders like this (notice the absence of shadows, it's flat):
Here's the code in cellforRowAtIndexPath:
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:#"BGImage"];
Where BGImage is the first image in this post, with shadows. What am I missing here?
you have to set Your Cell Background using bellow Delegate Method of UITableView:-
- (void)tableView: (UITableView*)tableView
willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{
UIImage *img = [UIImage imageNamed:#"yourImage.png"]; // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
cell.backgroundColor = backgroundColor;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
at your issue may be your image Height width and your cell height width not same
I am using above method in my project set with bellow shaded image set in Cell:-
and its look like in project :-
Your shadow must be a part of your image.
You have to properly set the height and width.
I'd suggest you to create a custom UITableViewCell.
Add background image to your cell. It'll surely display the shadow.
I have a custom UITableView with its clearColor background. I'm setting the cell's backgroundView to a transparent UIImageView and setting the background image view's backgroundColor to [UIColor clearColor]. I'm also setting the cell's backgroundColor to [UIColor clearColor].
I want to make cell.backgroundview as transparent on selection. How to do that?
you can explicitly set a selectedBackgroundView property of the cell with a semitransparent or transparent content (UIimageview) so that i will not become opaque on selection
http://www.youtube.com/watch?v=PwcBdCUZNWs
i think thats what u r asking for just make the selectedView transparent from the UI properties
In your Cell creation :
cell.selectedBackgroundView =[[UIImageView alloc] init];
((UIImageView *)cell.selectedBackgroundView).image = [UIImage imageNamed:#"your transparent UIImage"];
or:
UIView *v = [[UIView alloc] init];
v.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = v;
I am trying to add a background image to UITableViewCell using the following code:
UIImage *bgImage=[UIImage imageNamed:#"green-cell-row.png"];
UIImageView *bgForFirst=[[UIImageView alloc] initWithImage:bgImage];
cell.backgroundView=bgForFirst;
[cell.contentView addSubview:venueDisplayImage];
[cell.contentView addSubview:venueDisplayName1];
[cell.contentView addSubview:venueDisplayName2];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
However, I get venueDisplayName on white space around it. What would be the best way to fix this and correctly add my background image?
Try this way:
1) TabelView set the background like:
tblView.backgroundView.alpha = 0.0;
tblView.backgroundColor=[UIColor clearColor];
2) Add the image view in cellForRowAtIndexPath og delegate method of tableview:
UIImageView *bckView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 300,80)];
cell.backgroundView.alpha = 0.0;
cell.backgroundColor=[UIColor clearColor];
bckView.image = [UIImage imageNamed:#"cell.png"];
bckView.contentMode = UIViewContentModeScaleToFill;
[cell.contentView addSubview:bckView];
Did you try to change backgroundColor or venueDisplayName to [UIColor clearColor] or to [UIColor greenColor]?
For performance reasons try to avoid using non-opaque views in UITableViewCell.
You have to use the property of cell
there are 2 property you can use
1) cell.backgroundColor
2) cell.backgroundView
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageName:#""]];
In second case you have to set any view as a background view
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
I want to make the grouped UITableView transparent. I partially succeded with the following code:
UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
Unfortunately, black corners appeared in the rounded cells. How to get rid of them?
Instead of using
UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
Just use:
historyTable.backgroundColor = [UIColor clearColor];
That also clears up the memory leak you were creating.
remove UITableView backgroundView
xxx.backgroundView = nil;
This is necessary on iPad builds. When compiling to run on iPad and iPhone, check the tableView responds to the selector with ...
if ([self.tableView respondsToSelector:#selector(setBackgroundView:)]) {
[self.tableView setBackgroundView:nil];
}
for me it worked finaly after setting both to nil/clear:
[myTableView setBackgroundView:nil];
[myTableView setBackgroundColor:[UIColor clearColor]];
I had this issue and found that there was no difference between using:
[[UIColor alloc] initWithWhite:1 alpha:0.0];
and using:
[UIColor clearColor];
I tried both of these and still had the little black corners on my table view.
I also tried setting the backgroundView to nil as suggested, but this didn't work either.
I solved this by setting the backgrounds of the individual cells to transparent in the cellForRowAtIndexPath method:
cell.backgroundColor = [UIColor clearColor];
Of course, this has the side effect that your cells themselves are transparent, which isn't ideal for everyone, but it ok for me in this case.