, "" , , ! - . UITableView layoutSubviews :
- (void) layoutSubviews {
[super layoutSubviews];
const CGFloat PageCellBackgroundRadius = 6.0;
for(int i = 0; i < [self numberOfSections]; i++) {
NSInteger viewTag = i + 123456;
CGRect frameRect = [self shadowFrameForSection: i];
UIView* shadowBackgroundView = [self viewWithTag: viewTag];
if (shadowBackgroundView) {
if (!CGRectEqualToRect(frameRect, shadowBackgroundView.frame)) {
shadowBackgroundView.frame = frameRect;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath;
shadowBackgroundView.layer.shadowPath = shadowPath;
}
[self sendSubviewToBack: shadowBackgroundView];
} else {
shadowBackgroundView = [[[UIView alloc] initWithFrame: frameRect] autorelease];
shadowBackgroundView.tag = viewTag;
shadowBackgroundView.opaque = YES;
shadowBackgroundView.backgroundColor = [UIColor clearColor];
shadowBackgroundView.layer.shadowOpacity = 0.3;
shadowBackgroundView.layer.shadowRadius = 2;
shadowBackgroundView.layer.shadowColor = [[UIColor blackColor] CGColor];
shadowBackgroundView.layer.shadowOffset = CGSizeMake(0.0, 1.0);
CGPathRef shadowPath = [UIBezierPath bezierPathWithRoundedRect: shadowBackgroundView.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(PageCellBackgroundRadius, PageCellBackgroundRadius)].CGPath;
shadowBackgroundView.layer.shadowPath = shadowPath;
shadowBackgroundView.layer.shouldRasterize = YES;
[self addSubview: shadowBackgroundView];
}
}
}
:
- (CGRect) shadowFrameForSection: (NSInteger) section {
CGRect sectionFrame = [self rectForSection: section];
CGFloat sectionHeaderHeight = CGRectGetHeight([self rectForHeaderInSection: section]);
CGFloat sectionFooterHeight = CGRectGetHeight([self rectForFooterInSection: section]);
UIEdgeInsets contentInsets = UIEdgeInsetsMake(sectionHeaderHeight + 1, 10, sectionFooterHeight + 1, 10);
return UIEdgeInsetsInsetRect(sectionFrame, contentInsets);
}
!
UIViews UITableView , , UIView. UITableView
: "rectForSection" ..
, layoutSubviews! ( , else else = > ?)
CALayers, !
/ uiviews .
, , ..
, ..
"" , !
, !
, , !: -)