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]
Related
I loading all data in UITableView section.
i getting result of above screen. I want to remove black patch(background color) of table cell.
For that i write following code in cellForRowAtIndexPath method
cell.backgroundColor = [UIColor whiteColor];
[cell setOpaque:NO];
NSDictionary *name = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
[cell.textLabel setFont:[UIFont systemFontOfSize:15.0f]];
[cell.textLabel setText:[name objectForKey:#"Name"]];
and my nib file is
still i give same result. This code and nib setting worked fine on iPhone simulator but not in iPhone.
Please why this happen, where i m going to wrong way?
How i remove this problem?
Thanks in advanced.
Change the Background of View, in your nib, make it clear Color or white Color
also try
in method CellForRowAtIndexPath, like tableView.backgroundColor = [UIColor clearColor];
hi RRB
You have to set clearColor of your tableView.backgroundColor run time not in xib.
how to set different background colors for cells in a UITableView
(specifically rainbow color for seven cells)
Set the backgroundColor property:
cell.backgroundColor = [UIColor redColor];
Note that the backgroundColor must be set in the tableView:willDisplayCell:forRowAtIndexPath: method (from UITableViewCell reference):
Note: If you want to change the
background color of a cell (by setting
the background color of a cell via the
backgroundColor property declared by
UIView) you must do it in the
tableView:willDisplayCell:forRowAtIndexPath:
method of the delegate and not in
tableView:cellForRowAtIndexPath: of
the data source. Changes to the
background colors of cells in a
group-style table view has an effect
in iOS 3.0 that is different than
previous versions of the operating
system. It now affects the area inside
the rounded rectangle instead of the
area outside of it.
Use the indexPath parameter to achieve the rainbow effect.
If you want to set cell color based on some state in the actual cell data object, then this is another approach:
If you add this method to your table view delegate:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = cell.contentView.backgroundColor;
}
Then in your cellForRowAtIndexPath method you can do:
if (myCellDataObject.hasSomeStateThatMeansItShouldShowAsBlue) {
cell.contentView.backgroundColor = [UIColor blueColor];
}
This saves having to retrieve your data objects again in the willDisplayCell method.
Do not forget to set background color of your tableView to clearColor. Otherwise the clearColor of cell will not be displayed as the background color of tableView will be whiteColor by default. And even when the cell color turns to clearColor whiteColor will be displayed because the tableView background color is still whiteColor. Remenber.
You can set it like so:
cell.contentView.backgroundColor = [UIColor colorWithRed:249.0/255 green:237.0/255 blue:224.0/255 alpha:1.0];
Pretty sure UITableViewCell is a subclass of UIView, so:
cell.backgroundColor = [UIColor blueColor];
For awful rainbow colors, here is an example:
static NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor yellowColor], etc..., nil];
cell.backgroundColor = [colors objectAtIndex:indexPath.row];
Try this
cell.backgroundVIew.backgroundColor = [UIColor orangeColor];
If you've subclassed UITableViewCell, you can reliably set self.backgroundColor in -layoutSubviews. At least in my experience, this works in the odd cases where tableView:willDisplayCell:forRowAtIndexPath: does not.
You may arrive at the conclusion that 'willDisplayCell' is still not working like I did at first. The reason it didn't work for me initially was because I wasn't using colors properly.
Don't forget that when using custom colors you need to divide by 255.0f:
[UIColor colorWithRed:44/255.0f green:50/255.0f blue:65/255.0f alpha:1];
Something like the following will result to a white cell:
//DON'T DO
[UIColor colorWithRed:44 green:50 blue:65 alpha:1];
making it look like it's not doing anything when it really is setting the background to white.
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...
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.
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];
...
}