How can I create a transparent tableview with each cells being transparent? - iphone

I tried all this inside
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
1.tableView.backgroundColor = [UIColor clearColor];
2.cell.backgroundColor = [UIColor clearColor];
3.cell.contentView.backgroundColor = [UIColor clearColor];
It only responds to the 1st line and makes the background a translucent kind of black. What should I do to get 100% transparency?

I've had this same problem before. As suggested in a comment, try [setOpaque:NO]
If push comes to shove, make a simple 1px clear .png. Then, make a stretchable UIImage with it, and say [setBackgroundView:imageViewWithClearImage]. That's a bit hacky, though.

Related

iPhone AppStore's UITableViewCell background colours

I wanted to test out some different coloured cells in my iPhone App, and I thought that the same coloured cells as the app store ones would probably suit. Therefore I wanted to try them out. Unfortunately I do not have the colour codes for the cells, does anyone know?
These are the colours in action:
Also, would this code be correct to show them?
- (void)tableView: (UITableView *)tableView willDisplayCell: (UITableViewCell *)cell forRowAtIndexPath: (NSIndexPath *)indexPath {
if ( indexPath.row%2 == 0) {
UIColor *altCellColor = [UIColor colorWithRed:256/256.0 green:237/256.0 blue:227/256.0 alpha:1.0]; /
cell.backgroundColor = altCellColor;
}
if ( indexPath.row%2 == 1) {
UIColor *altCellColor2 = [UIColor colorWithRed:1 green:1 blue:1alpha:1.0];
cell.backgroundColor = altCellColor2;
}
The code you posted looks like it'll work. The two colors you're looking for are
[UIColor colorWithRed:.678 green:.678 blue:.69 alpha:1]
and
[UIColor colorWithRed:.596 green:.596 blue:.612 alpha:1]
If you are working on mac then, just search fo Digital Color Meter in spotlight(this app in Application's utility). This application will give you any RGB and other color code value that you want.
Thanks
you can use this code. it's worked for me
[UIColor colorWithRed:172.0/255.0 green:217.0/255.0 blue:246.0/255.0 alpha:1]

iPhone, how can I make my UITableView cells black with and without data in them?

I'm managed to make my UITableView rows / cells black when data is loaded, to a fashion, I get a white line in between rows, which makes it look awful. How can i make them fully black with and without data ?
Heres the code I'm using at the moment
- (void)tableView:(UITableView *)tableView willDisplayCell:
(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor blackColor];
}
Heres what I get (with white lines remaining) :(
Change the separator style of your table view.
yourTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
You can do it in Interface Builder too on the properties palette.
-- Edit for clarity following comments below --
Set the entire tableView to have a black background:
[yourTableView setBackgroundColor:[UIColor blackColor]];
This can also be done in the Interface Builder properties panel.

iPhone : UITableViewCell: cell carry background color strip

When i used
self.view.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:#"image_name.png"]];
the cell carry bottom part of image and it looks like strip on view
Use the following method to set cell height exactly the same as your image's height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Also you might want to remove separators depending on how your image looks using the following code:
MyTableName.separatorStyle = UITableViewCellSeparatorStyleNone;

Altering the background color of cell.accessoryView and cell.editingAccessoryView

Whenever I add an accessoryView to my UITableViewCell, it doesn't carry the background color across? I'm setting a UISwitch as my accessoryView, and the color I have set in the cell.backgroundColor property only effects the contentView and not the accessoryView.
I have tried everything to set them to the same value. I tried to set the cell.backgroundView.backgroundColor and the cell.accessoryView.backgroundColor properties to the color I want but nothing is working. I also tried creating a subview inside contentView, which solved the backgroundColor problem (by avoiding it), but it creates the problem, where the switch sits on top of the cell.textLabel when the text is too long.
Is there are way I can modify the background color of the accessoryView without creating a subview in contentView, or to alter the length of the cell.textLabel without subclassing UITableViewCell?
Upon reading the documentation (a novel idea), I found the article, "A Closer Look at Table-View Cells". It helped me understand the composition of the cells, and I found my answer...
cells look like this...
Since the cell.accessoryView is a sister view to cell.contentView I had to ask the cell.contentView for its superview, and then I was able to change the background color for both views at once. Here's what the code looks like...
// Cell Formatting
cell.contentView.superview.backgroundColor = [UIColor greenColor];
I know it's really simple, but I'm a newbie and it took me ages to slow down and read the doc. Hopefully, this helps some other folks out there!
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor yellowColor];
}
UIView *myView = [[UIView alloc] initWithFrame:cell.frame];
myView.backgroundColor = [UIColor colorWithRed:214.00/255.00 green:233.00/255.00 blue:247.00/255.00 alpha:1.0];
cell.backgroundView = myView;
[myView release];
If you want to blend the accessory view background color with the background color of the cell, in iOS8 and Swift this worked like a charm in the tableView(_, cellForRowAtIndexPath:) method:
let color = cell.contentView.backgroundColor
cell.backgroundColor = color
#Zak, first of all thanks for bringing to my attention the details of the cell layout. Very helpful!
I would just like to point out that the following code:
self.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"cell_background.png"]];
worked for me. The result was a background image stretching over whole cell. AccessoryTypeView didn't cover it! Important part is to put this code into layoutSubviews method of your custom cell class and not into cellForRowAtIndexPath found in TableViewController class. In my case I defined a class CustomCell and inside of it I have defined labels, image views etc.
NOTE:The following code wasn't working:
cell.contentView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"cell_background.png"]];
when put inside tableView:(UITableView *)tableView cellForRowAtIndexPat method. It was giving me the background covering the cell but AccessoryTypeView was above it...

UITableViewCell color issues with custom table view background

I have a UITableView with a custom background image set like this:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]];
The background appears fine, but my UITableViewCells (default cells, not custom) have some sort of weird tint to them, and the UILabel containing the "New Project" text also seems to have some sort of background behind it. How can I remove this? I've already tried:
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
Thanks
alt text http://cl.ly/Cg5/content
I believe that this is a nasty side-effect of simply adding an image straight into your table view's backgroundColor.
Try adding the image to the view's background color:
[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]]];
and then set the table view's backgroundColor to be clear:
[[self tableView] setBackgroundColor:[UIColor clearColor]];
I hope this helps!
Some times when your working with setting images for an app, and testing on the simulator, they get frozen to the app for the few run. Not sure, this is the case even if you delete the image files; they still keep popping up.
I would make that you have rest the simulator, and restart Xcode. Then force a rebuild of the app back on the simulator. This should clear out any images- even background images if they are still being referenced.
If this is not a solution that works...try making sure that you don't have conflicting commands going to the same UiTablView object-(1 from IB and 1 from Xcode programmically). Sometimes you can overlook that you have set something in IB, and it conflicts with what your telling it to do programically.
If that doesn't solve the issue...check the connections in IB and make sure your reffrencing the correct IBOutlet UITableView *tableview. And you have the delegat and data protocols in the header.
If you want to have each cell set with background and want to remove text's background, maybe you can try this...
- (void)viewDidLoad {
...
self.tableView.backgroundColor = [UIColor clearColor];
...
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"mybg.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
...
}