I have an IBOutlet inside a custom table view cell.
@property (weak, nonatomic) IBOutlet UIView *innerContainer;
I want to override the getter as
-(UIView *)innerContainer
{
UIColor * shadowColor= [UIColor colorWithRed:199/255.0f
green:178/255.0f
blue:153/255.0f
alpha:1];
_innerContainer.layer.shadowOffset = CGSizeMake(0, 0);
_innerContainer.layer.shadowColor = [shadowColor CGColor];
_innerContainer.layer.shadowRadius = 4;
_innerContainer.layer.shadowOpacity = .75;
CGRect shadowFrame = _innerContainer.layer.bounds;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
_innerContainer.layer.shadowPath = shadowPath;
return _innerContainer;
}
but no effect seems to take place. On the other hand, if I add the shadow to innerContainer
inside
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
then the effect is there?
I tried adding @synthesize innerContainer=_innerContainer
but that made no difference.
Is there a way to override the getter of an IBOutlet?
This is not the correct approach. With your current code, the work to set up your shadow will be performed every time innerContainer
is accessed. It's probably not working because you don't access innerContainer
directly in your code, and the getter is never performed. On the other hand, if you do access the property multiple times, the work will be performed each time, which is overkill. Instead, override the awakeFromNib
method of your table view cell, and place this logic there. This method gets called as soon as all of your outlets have been established, and is the correct place for your logic to create the shadow.