Reputation: 75
The UITableView
I am using has a custom UItableViewCell
. This custom cell has a subview (an UIView subclass) to it. I use the drawRect
of the custom UIView subclass to place all the text to be displayed by the cell.
And in the drawRect
(of UIView
subclass) I do the following
/*
// This piece of code is called when setNeedsDisplay is called
*/
- (void)drawRect:(CGRect)rect
{
self.layer.cornerRadius = 10.0f;
self.layer.backgroundColor = [[UIColor orangeColor] CGColor];
self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
self.layer.borderWidth = 3.0f;
}
However my custom cell is a black square like this
But I do see the intended behavior if I select the row. Like shown below
Whats going on ?
Upvotes: 4
Views: 481
Reputation: 92
You are doing one mistake:
Please go to the view in side the UItableViewCell and check the background color it may be black or something others, Reset it to clear color then check your result,
Upvotes: 0
Reputation: 726539
Your drawRect:
method does not draw anything; the code that you put in there belongs in your initWithFrame:
implementation.
You should manipulate the layer configuration in the initializer; in your drawRect:
you should call functions of your CGContextRef
based on the state of the view. For example, to draw some text you would use CGContextShowTextAtPoint
, to draw some lines you would use CGContextAddLineToPoint
, and so on.
See this question for information on the relationship between drawRect:
and the CALayer
of your UIView
.
Upvotes: 3
Reputation: 10775
Try to set self.layer.masksToBounds = YES
and (maybe) self.opaque = NO
during your UIView
's (the one where drawRect
is overridden) initialization. (see this question)
Upvotes: 0
Reputation: 3480
Try to disable the selection highlight of the cell by using
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Upvotes: 0