mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Make SectionHeaderView subclass from UITableViewHeaderFooterView
This commit is contained in:
@@ -17,10 +17,17 @@
|
||||
|
||||
#import "SectionHeaderView.h"
|
||||
|
||||
#import "GeneratedInterface-Swift.h"
|
||||
|
||||
static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
|
||||
@implementation SectionHeaderView
|
||||
|
||||
+ (NSString*)defaultReuseIdentifier
|
||||
{
|
||||
return NSStringFromClass([self class]);
|
||||
}
|
||||
|
||||
- (void)setMinimumLeftInset:(CGFloat)minimumLeftInset
|
||||
{
|
||||
_minimumLeftInset = minimumLeftInset;
|
||||
@@ -41,25 +48,53 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
|
||||
- (void)setTopSpanningView:(UIView *)topSpanningView
|
||||
{
|
||||
// remove old one
|
||||
[_topSpanningView removeFromSuperview];
|
||||
_topSpanningView = topSpanningView;
|
||||
if (_topSpanningView)
|
||||
{
|
||||
// add new one
|
||||
[self.contentView addSubview:_topSpanningView];
|
||||
}
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setHeaderLabel:(UILabel *)headerLabel
|
||||
{
|
||||
// remove old one
|
||||
[_headerLabel removeFromSuperview];
|
||||
_headerLabel = headerLabel;
|
||||
if (_headerLabel)
|
||||
{
|
||||
// add new one
|
||||
[self.contentView addSubview:_headerLabel];
|
||||
}
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setAccessoryView:(UIView *)accessoryView
|
||||
{
|
||||
// remove old one
|
||||
[_accessoryView removeFromSuperview];
|
||||
_accessoryView = accessoryView;
|
||||
if (_accessoryView)
|
||||
{
|
||||
// add new one
|
||||
[self.contentView addSubview:_accessoryView];
|
||||
}
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setBottomView:(UIView *)bottomView
|
||||
{
|
||||
// remove old one
|
||||
[_bottomView removeFromSuperview];
|
||||
_bottomView = bottomView;
|
||||
if (_bottomView)
|
||||
{
|
||||
// add new one
|
||||
[self.contentView addSubview:_bottomView];
|
||||
}
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
@@ -88,6 +123,15 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
|
||||
{
|
||||
if (self = [super initWithReuseIdentifier:reuseIdentifier])
|
||||
{
|
||||
[self setup];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setup
|
||||
{
|
||||
_minimumLeftInset = 20;
|
||||
@@ -95,21 +139,24 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
_topViewHeight = 30;
|
||||
}
|
||||
|
||||
- (void)prepareForReuse
|
||||
{
|
||||
[self.contentView vc_removeAllSubviews];
|
||||
[super prepareForReuse];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
CGFloat _leftInset = 0.0, _rightInset = 0.0;
|
||||
|
||||
_leftInset += self.safeAreaInsets.left;
|
||||
_rightInset += self.safeAreaInsets.right;
|
||||
|
||||
CGFloat leftMargin = MAX(_leftInset, _minimumLeftInset);
|
||||
CGFloat rightMargin = MAX(_rightInset, _minimumRightInset);
|
||||
CGFloat leftMargin = _minimumLeftInset;
|
||||
CGFloat rightMargin = _minimumRightInset;
|
||||
|
||||
if (_topSpanningView)
|
||||
{
|
||||
CGRect frame = self.bounds;
|
||||
CGRect frame = self.contentView.bounds;
|
||||
frame.size.height = _topViewHeight;
|
||||
_topSpanningView.frame = frame;
|
||||
}
|
||||
@@ -130,9 +177,9 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
else
|
||||
{
|
||||
// center header label vertically
|
||||
frame.origin.y = MAX(0, (self.bounds.size.height - frame.size.height)/2);
|
||||
frame.origin.y = MAX(0, (self.contentView.bounds.size.height - frame.size.height)/2);
|
||||
}
|
||||
frame.size.width = self.bounds.size.width - leftMargin - rightMargin;
|
||||
frame.size.width = self.contentView.bounds.size.width - leftMargin - rightMargin;
|
||||
_headerLabel.frame = frame;
|
||||
}
|
||||
|
||||
@@ -143,7 +190,7 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
rightMargin = MAX(_rightInset, 20);
|
||||
|
||||
CGRect frame = _accessoryView.frame;
|
||||
frame.origin.x = self.bounds.size.width - frame.size.width - rightMargin;
|
||||
frame.origin.x = self.contentView.bounds.size.width - frame.size.width - rightMargin;
|
||||
frame.origin.y = MAX(0, (_topViewHeight - frame.size.height)/2);
|
||||
_accessoryView.frame = frame;
|
||||
}
|
||||
@@ -157,8 +204,8 @@ static const CGFloat kInterItemsSpaceHorizontal = 8.0;
|
||||
CGRect frame = _bottomView.frame;
|
||||
frame.origin.x = leftMargin;
|
||||
frame.origin.y = CGRectGetMaxY(_headerLabel.frame);
|
||||
frame.size.width = self.bounds.size.width - leftMargin - rightMargin;
|
||||
frame.size.height = self.bounds.size.height - frame.origin.y;
|
||||
frame.size.width = self.contentView.bounds.size.width - leftMargin - rightMargin;
|
||||
frame.size.height = self.contentView.bounds.size.height - frame.origin.y;
|
||||
_bottomView.frame = frame;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user