Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to set custom insets on the header #25

Merged
merged 3 commits into from
Oct 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions BPForms/BPFormViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ typedef NS_ENUM(NSInteger, BPFormKeyboardMode) {
*/
@property (nonatomic, strong) NSArray *formCells;

/**
* Set this to use a custom insets for headers
*/
@property (nonatomic, assign) UIEdgeInsets customSectionHeaderInsets;

/**
* Set this to use a custom insets for footers
*/
@property (nonatomic, assign) UIEdgeInsets customSectionFooterInsets;

/**
* Set this to use a custom height for headers
*/
Expand Down
27 changes: 23 additions & 4 deletions BPForms/BPFormViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)setupFormVC {
self.sectionHeaderTitles = [NSMutableDictionary dictionary];
self.sectionFooterTitles = [NSMutableDictionary dictionary];

self.customSectionHeaderInsets = UIEdgeInsetsZero;
self.customSectionHeaderHeight = 0.0;
self.customSectionFooterHeight = 0.0;
}
Expand Down Expand Up @@ -304,12 +305,21 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
NSString *headerTitle = self.sectionHeaderTitles[@(section)];
if (headerTitle) {
CGFloat headerHeight = self.customSectionHeaderHeight ?: [self.tableView sectionHeaderHeight];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.frame.size.width, headerHeight)];

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), headerHeight)];
CGFloat labelWidth = UIEdgeInsetsEqualToEdgeInsets(self.customSectionHeaderInsets, UIEdgeInsetsZero) ? CGRectGetWidth(self.tableView.frame) :
CGRectGetWidth(self.tableView.frame) - (self.customSectionHeaderInsets.left + self.customSectionHeaderInsets.right);

CGFloat labelHeight = headerHeight - (self.customSectionHeaderInsets.top + self.customSectionHeaderInsets.bottom);
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.customSectionHeaderInsets.left, self.customSectionHeaderInsets.top, labelWidth, labelHeight)];
infoLabel.text = headerTitle;
infoLabel.textColor = [BPAppearance sharedInstance].headerFooterLabelTextColor;
infoLabel.font = [BPAppearance sharedInstance].headerFooterLabelFont;
infoLabel.textAlignment = NSTextAlignmentCenter;
return infoLabel;
infoLabel.numberOfLines = 0;

[headerView addSubview:infoLabel];
return headerView;
}
return [[UIView alloc] initWithFrame:CGRectZero];
}
Expand All @@ -325,12 +335,21 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger
NSString *footerTitle = self.sectionFooterTitles[@(section)];
if (footerTitle) {
CGFloat footerHeight = self.customSectionFooterHeight ?: [self.tableView sectionFooterHeight];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.frame.size.width, footerHeight)];

UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), footerHeight)];
CGFloat labelWidth = UIEdgeInsetsEqualToEdgeInsets(self.customSectionFooterInsets, UIEdgeInsetsZero) ? CGRectGetWidth(self.tableView.frame) :
CGRectGetWidth(self.tableView.frame) - (self.customSectionFooterInsets.left + self.customSectionFooterInsets.right);

CGFloat labelHeight = footerHeight - (self.customSectionFooterInsets.top + self.customSectionFooterInsets.bottom);
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.customSectionFooterInsets.left, self.customSectionFooterInsets.top, labelWidth, labelHeight)];
infoLabel.text = footerTitle;
infoLabel.textColor = [BPAppearance sharedInstance].headerFooterLabelTextColor;
infoLabel.font = [BPAppearance sharedInstance].headerFooterLabelFont;
infoLabel.textAlignment = NSTextAlignmentCenter;
return infoLabel;
infoLabel.numberOfLines = 0;

[footerView addSubview:infoLabel];
return footerView;
}
return [[UIView alloc] initWithFrame:CGRectZero];
}
Expand Down