background for uitableview cell - ios

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];

Related

Select row and change button color

In My tableview, cell is custom cell and I have button and label inside it.
lable and button background color is Green.
When I click on Particular row then Button color change and label background color is as it is. Here I used following code to set label background color via layer,
cell.lblCountMsg.backgroundColor = [UIColor clearColor];
cell.lblCountMsg.layer.backgroundColor = [UIColor colorWithRed:110/255.0 green:189/255.0 blue:82/255.0 alpha:1.0].CGColor;
but, same code is not working for Button. i tried with layer also
cell.btnTeting.backgroundColor = [UIColor clearColor];
cell.btnTeting.layer.backgroundColor = [UIColor colorWithRed:110/255.0 green:189/255.0 blue:82/255.0 alpha:1].CGColor;
but not set green color and also changed the color of selection color.
See, My Screen Shot (Breaking new) is Green.
Please help me to find solution.
Thanks in Advance.
You should implement didSelectRowAtIndexPath something like,
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Here your custom cell's class instead of UITableViewCell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.btn.backgroundColor = [UIColor redColor];
}
If you made a UITableViewCell subclass, try overriding the
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
method. In this method you can change your views in the cell when the cell is highlighted.
So for example:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
self.btnTeting.backgroundColor = [UIColor colorWithRed:110/255.0 green:189/255.0 blue:82/255.0 alpha:1.0];
}
UPDATED
#interface SuggestedGroupCell ()
#property (strong, nonatomic) IBOutlet UIButton *btnSubScribe;
#end
#implementation SuggestedGroupCell
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
self.btnSubScribe.backgroundColor = [UIColor colorWithRed:110/255.0 green:189/255.0 blue:82/255.0 alpha:1.0];
}
#end
If you want to change background color of button,remove this line and then try:
cell.btnTeting.layer.backgroundColor = [UIColor colorWithRed:110/255.0 green:189/255.0 blue:82/255.0 alpha:1].CGColor;
But if you want to change button title color you can write code like this:
[cell.btnMorePupils setTitleColor:[UIColor redColor] forState:UIControlStateNormal]
Here UIControlState you can take what ever like UIControlStateNormal, UIControlStateSelected etc as per your requirement.

UITableView weird separator line color

i have a problem in setting UITableViewCell background color. I wanna change it into my own color, so I use this code to change that background color :
UIView *bg = [[UIView alloc] init];
bg.backgroundColor = [ColorManager backgroundInput];
bg.layer.masksToBounds = YES;
[cell setSelectedBackgroundView:bg];
I implement this code in CellForRowAtIndexPath method.
The weird thing I have is, when i tap into a cell, the separator line color being highlight just like the image below. I just wanna make it still dark, anybody have idea?
Thank you
After setting up your own background view,which will have the line or not,
you can clear the default tableview color
tablename.separatorColor = [UIColor clearColor];
OR
If you don't want to remove the default line then you can give same color of background view to line color
//You can specify the RGB of background view
tablename.separatorColor = [UIColor colorWithRed:R green:G blue:B alpha:1.0f];
I think the best option is
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Another option is to set the backgroundColor of the UITableViewCell to a clear color.
cell.backgroundColor = [UIColor clearColor];
try it
Objective-c
tablename.separatorColor = [UIColor blackColor];
Swift
tablename.separatorColor = UIColor.blackColor();

cannot set background color of UITableViewCell in iOS6?

I started testing my app under simulator, because I don't have any iOS 6 device and stumbled upon weird problem. I cannot set backgroundColor property of UITableViewCell. If I st this:
cell.contentView.backgroundColor = [UIColor redColor];
it is working only for iOS 6, when I use this:
cell.backgroundColor = [UIColor redColor];
or this
[cell setBackgroundColor:[UIColor redColor]];
it is working only for iOS7.
When I use both cell.contentView and cell.backgroundColor it's working for both iOS... shouldn't it be one answer for such a 'easy' property? Or maybe it's some simulator bug?
UPDATE:
If it changes anything in the same tableview and cells I cannot set accessoryType neither via StoryBoard nor code...
UPDATE2: for some reason setting tableview style to plain deleted all my changes, but grouped showed as expected...
In iOS6 you need to change the cell's backgroundColor in willDisplayCell.
This works in iOS7 as well, precluding the need for version-specific code.
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor redColor]];
}
I don't see the problem in setting the background for the contentView AND directly to the cell. iOS 7 has change a lot this class. If you need to be compatible with old systems then you need to do this type of things.
So yes, you should use both:
cell.contentView.backgroundColor
cell.backgroundColor
Try to change the cell's backgroundView color not the backgroundColor.
UIView *myView = [[UIView alloc] init];
myView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = myView;
If you set (assuming you use standard cell):
cell.textLabel.backgroundColor = [UIColor clearColor];
...then you just have to use:
cell.contentView.backgroundColor = [UIColor redColor];
iOS 6 seems to copy table's background color to textLabel.
try to add this code:
cell.backgroundView.backgroundColor = [UIColor clearColor];

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

ABTableViewCell selected lag

I've successfuly subclassed ABTableViewCell for fast scrolling.
I really recommend it to anyone who's making an app with big tableViews...
http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
My problem with it is that when I tap a row, there is a small delay until it gets selected. I tried to put [cell setSelected:true] in the didSelectRowAtIndexPath method of the tableView, and it still lags. Has anyone experienced this as well with a ABTableViewCell subclass?
I didn't have this issue using regular UITableViewCells.
A cell can be highlighted (on touchDown) or selected (on touchUp).
Code that came with ABTableViewCell:
if(self.selected) {
backgroundColor = [UIColor clearColor];
greyColor = [UIColor whiteColor];
blackColor = [UIColor whiteColor];
}
Had to replace it with:
if(self.highlighted || self.selected) {
backgroundColor = [UIColor clearColor];
greyColor = [UIColor whiteColor];
blackColor = [UIColor whiteColor];
}
And that killed the cell selection lag.

Resources