Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Caleb Kleveter
Treehouse Moderator 37,862 PointsGive a UICollectionViewCell the blur property as a background.
I am attempting to make the background of a UICollectionViewCell blurry/transparent. I am looking at these Stack Overflow posts:
http://stackoverflow.com/questions/24067719/how-to-use-uivisualeffectview http://stackoverflow.com/questions/24424165/how-to-implement-uivisualeffectview-in-uitableview-with-adaptive-segues
I am also watching the video on custom cells from the Photo Bombers app again.
This is what I have so far:
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
visualEffectView.frame = self.maskView.bounds;
[UIImageView addSubview:visualEffectView];
}
}
- (void)layoutSubviews {
self.maskView.frame = self.contentView.bounds;
}
I am getting an error when I try to add a subview:
No known class method for selector 'addSubview'
2 Answers
Stefan Cimander
37,115 PointsOkay, you don't want to add the effect to an image but to the UICollectionViewCell instead, sorry my mistake.
Try to add the effect view to the instance of the cell like this:
[self addSubview: visualEffectView];
Does it work that way?
Stefan Cimander
37,115 PointsI hope I'm getting your problem right, but in order to call addSubview:, you first need an object of type UIView. In this case, there is missing a concrete imageView (of type UIImageView) the visualEffectView should be added to.
Try to replace the line:
[UIImageView addSubview: visualEffectView];
by something like this:
// Use the imageView object instead of UIImageView class:
[imageView addSubview: visualEffectView];
Caleb Kleveter
Treehouse Moderator 37,862 PointsThat didn't do it, I got this error:
Unknown receiver 'imageView'; did you mean 'UIImageView'?
You can also use swift if you want.
Caleb Kleveter
Treehouse Moderator 37,862 PointsCaleb Kleveter
Treehouse Moderator 37,862 PointsIt worked! Thanks!