How to make cell transparent on selection - iphone

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;

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.

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 make semi-transparent UITableViewCells?

I hope to add image to cell background and from the semi transparent cell I could see the backgroud of tableview.
From following topic, I know how to make transparent cell.
UITableViewCell transparent background (including imageView/accessoryView)
I've tried above, it did work. But when I add the following code:
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha: .4];
cell.backgroundView = backView;
The cell became grey color without any transparency, if I change code as follows,
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
The cell became white, still without any transparency.
Is there one can give me any clues?
To make your UITableViewCells Semi-Transparent that is Translucent, you have to make your UITableViewCells Transparent and then, set cell's backgroundView to an image which has translucent properties. Also set selectedBackgroundView of the cell to an image which is translucent and gives a selected cell's effect.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.text.backroundColor = [UIColor clearColor]; //if you have labels on cells..
cell.backgroundView = backView;
Then set an image with translucent effect on our transparent cell..
UIImageView *cellImage = [[UIImageView alloc] init];
[cellImage setImage:[UIImage imageNamed: #"unselectedCellImage.png"]];
[cell setBackgroundView:cellImage];
[cellImage release];
Then set an image for selected cell to give an translucent effect after selection also..
UIImageView *cellImageSelection = [[UIImageView alloc] init];
[cellImageSelection setImage:[UIImage imageNamed: #"selectedCellImage.png"]];
[cell setSelectedBackgroundView:cellImageSelection];
[cellImageSelection release];
It'll work..
Cheers..
You can try this one
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha: .2];
cell.backgroundView = backView;
What you did wrong was you choose .1 .1 .1 which is for black color you need 255 255 255 for the white color and your opacity was very high so it looked gray color to you actually it was black with opacity. Hope this helps :)
Views are initialized as opaque by default, so you probably need to explicitly set backView.opaque = NO; in order for it to draw with any transparency.

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

How to remove the white background of UITableViewCell

I want to remove the default white background of UITableViewCell like I want the background of the cell being transparent so that it shows the actual background of the window.
I Got it.
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;