BackgroundColor of UItableviewCell Notworking - ios

I am setting the Background color of my uitableviewCell like
cell.contentView.backgroundColor = [UIColor colorWithRed:8.0 green:210.0 blue:11.0 alpha:1.0];
its not working, however, if i do like
cell.contentView.backgroundColor = [UIColor grayColor];
it works then. Any help

UIColor has to be defined between 0 and 1 to get the RGB value to work (UIColor class reference):
cell.contentView.backgroundColor = [UIColor colorWithRed:8.0f/255.0f green:210.0f/255.0f blue:11.0f/255.0f alpha:1.0f];

Related

background for uitableview cell

MyTableCell *cell=[[MyTableCell alloc]init];
cell.backgroundColor = [UIColor clearColor];
The above lines of code are still showing the white color of the cell's background and hiding the background image of the tableview.
Go to you storyboard and set the color of your uitableview cell to clear color from there.And also set uitabelview color also to clear color.
Or in you viewdidload set tableview background color to clear color and in cellforrow at indexparth delagate set
cell.contentView.backGroundColor = [UIColor ClearColor]
try this
- (void)tableView:(UITableView *)tableView willDisplayCell(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
}
set the contentview background color also
cell.contentView.backGroundColor = [UIColor ClearColor];
cell.backGroundView.backGroundColor = [UIColor ClearColor];
cell.selectedBackGroundView.backGroundColor = [UIColor ClearColor];
Also check if you cleared the tableView.backGroundColor also
Thank you every one. I have solved the problem. I changed the background attribute in the attribute inspector in the storyboard for my cell object from default to clear color and it worked.
You can do it this way
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView.backgroundColor = [UIColor clearColor];

how to add colour in verticalSeprator UITable

How i can add specific colour in verticalSeperator UITable.I tried with UIColor option but its not working please help me to solve this.
HJTextFieldCell *cell = (HJTextFieldCell *)[_tableView dequeueReusableCellWithIdentifier:textCellIdentifier];
cell.constraint_leftSideOftxtFild.constant = 10.0f;
cell.constraint_heigntOfTxtField.constant = 30.0f;
cell.lbl_verticalSeprator.hidden =NO;
cell.lbl_verticalSeprator.textColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.098/255.0 alpha:0.22];
Try with background color not text color.
cell.lbl_verticalSeprator.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.098/255.0 alpha:0.22];
and the best way is to use native separator and you can change the color with tableView.separatorColor of UITableview

Alternate between 3 colors in UITableviewCell

I have a UITableView that I would like to display in 3 different background colors. Basically white, light gray, dark gray, then back to white and so on.
This is all I have been able to find on stack overflow so far:
if (indexPath.row % 2) {
cell.contentView.backgroundColor = [UIColor lightGrayColor];
} else {
cell.contentView.backgroundColor = [UIColor darkGrayColor];
}
This works perfect for 2 colors. How can I alternate between 3 colors?
Just use 3 instead of 2 and then set the values accordingly, e.g.:
NSInteger colorIndex = indexPath.row % 3;
switch (colorIndex) {
case 0:
cell.contentView.backgroundColor = [UIColor whiteColor];
break;
case 1:
cell.contentView.backgroundColor = [UIColor lightGrayColor];
break;
case 2:
cell.contentView.backgroundColor = [UIColor darkGrayColor];
break;
}
You can also use [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0] with whatever numeric values you want if you want a more shades of gray (e.g. 50).
Rob is correct but i will use default color provided by UIColor:
NSInteger colorIndex = indexPath.row % 3;
switch (colorIndex) {
case 0:
cell.contentView.backgroundColor = [UIColor whiteColor];
break;
case 1:
cell.contentView.backgroundColor = [UIColor lightGrayColor];
break;
case 2:
cell.contentView.backgroundColor = [UIColor darkGrayColor];
break;
}
Try this:
if(indexPath.row % 3 ==0){
cell.contentView.backgroundColor = [UIColor whiteColor];
}
if((indexPath.row-1) % 3 ==0){
cell.contentView.backgroundColor = [UIColor lightGrayColor];
}
if((indexPath.row - 2) % 3 ==0){
cell.contentView.backgroundColor = [UIColor darkGrayColor];
}

Getting rid of cell text background box

I have this table:
How do I get rid of the boxes behind the text?
This is my current code:
UIColor *CellColor = [UIColor colorWithWhite:0.7 alpha:0.2];
cell.backgroundColor = CellColor;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont systemFontOfSize:16.0];
cell.textLabel.textAlignment = UITextAlignmentRight;
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10.0];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = #"Title text...";
cell.detailTextLabel.text = #"Subtitle text...";
Default background color for a UILabel is white. So this is normal.
If you want a transparent background, you need to use:
cell.textLabel.backgroundColor = [ UIColor clearColor ];
And same for detailTextLabel

UItableview cell background color

Hey guys i want to make the background of my cell color to be like this
.check the attached image.
thanks
u have to use gradients to get this look.take a look at this tutorial (gradients part) http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients
INSIDE cellforrowind.... function
cell.contentView.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor lightGrayColor];
or
[UIColor colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha];
change those value with red ,green blue ,alpha

Resources