So I'm facing an issue with setting a custum selectedBackgroundView inside my UITableViewCell
.
My cell has a contentView
that basically is a UIView
(frame = 0,0,80,70) with a black background and an UIImageView
as a subview.
The imageView's contentMode = UIViewContentModeScaleAspectFit;
This looks something like this:
Now I set the selectedBackgroundView like this:
//set the custom selected color
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = MY_TINT_COLOR;
CGColorRef darkColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha: 0.25].CGColor;
CGColorRef lightColor = [self.view.backgroundColor colorWithAlphaComponent:0.0].CGColor;
//setting some gradients here
//should not be relevant for the question
[cell setSelectedBackgroundView:bgColorView];
This results in something like this:
My question now is why the selectedBackgroundView
hides the black part of the contentView
?
I have already tried initializing my bgColorView
with a frame starting at x = 80
, but this does not change anything.
Also I have tried to explictly set the backgroundColor
of the imageView
to black, same result.
What could cause this behaviour?
Following figure gives the idea of a cell structure. The selected Background view will hide Content view
So you can give a try by setting background color of cell as black. Your custom cell looks something like this
self.backgroundColor = [UIColor blackColor]; // Gives black background for you
// Set selected background view
UIView *backgroundView = [[UIView alloc]initWithFrame:self.bounds];
backgroundView.layer.borderColor = [[UIColor colorWithRed:0.529 green:0.808 blue:0.922 alpha:1]CGColor];
backgroundView.layer.borderWidth = 10.0f;
self.selectedBackgroundView = backgroundView;
[backgroundView release];
// Set the content view
CGRect frame = CGRectMake(self.bounds.origin.x+5, self.bounds.origin.y+5, self.bounds.size.width-10, self.bounds.size.height-10);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageView = imageView;
[imageView release];
self.imageView.contentMode = UIViewContentModeScaleAspectFill ;
self.imageView.clipsToBounds = YES;
[self.contentView addSubview:self.imageView];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With