#import <UIKit/UIKit.h>
@interface YGSectionHeaderView : UIView
@property NSUInteger section;
@property (nonatomic, weak) UITableView *tableView;
@end
#import "YGSectionHeaderView.h"
@implementation YGSectionHeaderView
- (void)setFrame:(CGRect)frame{
CGRect sectionRect = [self.tableView rectForSection:self.section];
CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame));
[super setFrame:newFrame];
}
@end
像这样用。。。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
YGSectionHeaderView *sectionHead = [[YGSectionHeaderView alloc] init];
sectionHead.section = section;
sectionHead.tableView = tableView;
return sectionHead;
}