diff --git a/WordPress-iOS-Shared.podspec b/WordPress-iOS-Shared.podspec index 1ac7beb..735924c 100644 --- a/WordPress-iOS-Shared.podspec +++ b/WordPress-iOS-Shared.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPress-iOS-Shared" - s.version = "0.4.1" + s.version = "0.4.2" s.summary = "Shared components used in building the WordPress iOS apps and other library components." s.description = <<-DESC diff --git a/WordPress-iOS-Shared.xcodeproj/project.pbxproj b/WordPress-iOS-Shared.xcodeproj/project.pbxproj index a374a94..495e0cc 100644 --- a/WordPress-iOS-Shared.xcodeproj/project.pbxproj +++ b/WordPress-iOS-Shared.xcodeproj/project.pbxproj @@ -26,8 +26,7 @@ 931A1023192A9DFC00D3CC11 /* WPStyleGuide.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A1022192A9DFC00D3CC11 /* WPStyleGuide.m */; }; 931A1026192A9E0B00D3CC11 /* WPNUXUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A1025192A9E0B00D3CC11 /* WPNUXUtility.m */; }; 931A1029192A9E2400D3CC11 /* WPTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A1028192A9E2400D3CC11 /* WPTableViewCell.m */; }; - 931A102E192A9E3200D3CC11 /* WPTableViewSectionFooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A102B192A9E3200D3CC11 /* WPTableViewSectionFooterView.m */; }; - 931A102F192A9E3200D3CC11 /* WPTableViewSectionHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A102D192A9E3200D3CC11 /* WPTableViewSectionHeaderView.m */; }; + 931A102E192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A102B192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.m */; }; 931A1035192AA03600D3CC11 /* UIColor+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A1034192AA03600D3CC11 /* UIColor+Helpers.m */; }; 931A1038192AA34300D3CC11 /* WPImageSourceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A1037192AA34300D3CC11 /* WPImageSourceTest.m */; }; 931A103B192AA35B00D3CC11 /* AsyncTestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 931A103A192AA35B00D3CC11 /* AsyncTestHelper.m */; }; @@ -93,10 +92,8 @@ 931A1025192A9E0B00D3CC11 /* WPNUXUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WPNUXUtility.m; path = Core/WPNUXUtility.m; sourceTree = ""; }; 931A1027192A9E2400D3CC11 /* WPTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WPTableViewCell.h; path = Core/WPTableViewCell.h; sourceTree = ""; }; 931A1028192A9E2400D3CC11 /* WPTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WPTableViewCell.m; path = Core/WPTableViewCell.m; sourceTree = ""; }; - 931A102A192A9E3200D3CC11 /* WPTableViewSectionFooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WPTableViewSectionFooterView.h; path = Core/WPTableViewSectionFooterView.h; sourceTree = ""; }; - 931A102B192A9E3200D3CC11 /* WPTableViewSectionFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WPTableViewSectionFooterView.m; path = Core/WPTableViewSectionFooterView.m; sourceTree = ""; }; - 931A102C192A9E3200D3CC11 /* WPTableViewSectionHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WPTableViewSectionHeaderView.h; path = Core/WPTableViewSectionHeaderView.h; sourceTree = ""; }; - 931A102D192A9E3200D3CC11 /* WPTableViewSectionHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WPTableViewSectionHeaderView.m; path = Core/WPTableViewSectionHeaderView.m; sourceTree = ""; }; + 931A102A192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WPTableViewSectionHeaderFooterView.h; path = Core/WPTableViewSectionHeaderFooterView.h; sourceTree = ""; }; + 931A102B192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WPTableViewSectionHeaderFooterView.m; path = Core/WPTableViewSectionHeaderFooterView.m; sourceTree = ""; }; 931A1030192A9F3500D3CC11 /* WPTextFieldTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WPTextFieldTableViewCell.h; path = Core/WPTextFieldTableViewCell.h; sourceTree = ""; }; 931A1033192AA03600D3CC11 /* UIColor+Helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIColor+Helpers.h"; path = "Core/UIColor+Helpers.h"; sourceTree = ""; }; 931A1034192AA03600D3CC11 /* UIColor+Helpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIColor+Helpers.m"; path = "Core/UIColor+Helpers.m"; sourceTree = ""; }; @@ -243,10 +240,8 @@ 931A1022192A9DFC00D3CC11 /* WPStyleGuide.m */, 931A1027192A9E2400D3CC11 /* WPTableViewCell.h */, 931A1028192A9E2400D3CC11 /* WPTableViewCell.m */, - 931A102A192A9E3200D3CC11 /* WPTableViewSectionFooterView.h */, - 931A102B192A9E3200D3CC11 /* WPTableViewSectionFooterView.m */, - 931A102C192A9E3200D3CC11 /* WPTableViewSectionHeaderView.h */, - 931A102D192A9E3200D3CC11 /* WPTableViewSectionHeaderView.m */, + 931A102A192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.h */, + 931A102B192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.m */, 931A1030192A9F3500D3CC11 /* WPTextFieldTableViewCell.h */, FF8DDCE01B5E91050098826F /* WPTextFieldTableViewCell.m */, ); @@ -443,10 +438,9 @@ 9309B52D192BEECC00B69F69 /* WordPressShared.m in Sources */, 931A1016192A9D5200D3CC11 /* NSString+Util.m in Sources */, 931A1023192A9DFC00D3CC11 /* WPStyleGuide.m in Sources */, - 931A102F192A9E3200D3CC11 /* WPTableViewSectionHeaderView.m in Sources */, 598E770E1A8E3D1A0020DC05 /* WPDeviceIdentification.m in Sources */, 7462F3401961FAAB00CC8EED /* WPFontManager.m in Sources */, - 931A102E192A9E3200D3CC11 /* WPTableViewSectionFooterView.m in Sources */, + 931A102E192A9E3200D3CC11 /* WPTableViewSectionHeaderFooterView.m in Sources */, 744DA846194F3A76002CD6E9 /* UIImage+Util.m in Sources */, 931A1020192A9DD500D3CC11 /* WPNoResultsView.m in Sources */, 931A1026192A9E0B00D3CC11 /* WPNUXUtility.m in Sources */, diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.h b/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.h deleted file mode 100644 index 9fe55ad..0000000 --- a/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.h +++ /dev/null @@ -1,22 +0,0 @@ -#import - -@interface WPTableViewSectionFooterView : UITableViewHeaderFooterView - -@property (nonatomic, strong) NSString *title; -@property (nonatomic, assign) NSTextAlignment titleAlignment; - -// By default, fixedWidth will be enabled, which means for iPads -// the title label width will be <= WPTableViewFixedWidth. There -// will be equal padding before and after the label, if you want the label -// to have a default padding and a full width instead, you can disable the fixedWidth flag. -@property (nonatomic) BOOL fixedWidthEnabled; - -// By default, fixedWidth flag will assumed to be enabled and the title label width -// will be treated for <= WPTableViewFixedWidth for iPads. -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width; - -// If you disable the fixedWidth flag for the instance, you should pass `NO` as the -// fixedWidthEnabled parameter, so it will use the full width for the calculation -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width fixedWidthEnabled:(BOOL)fixedWidthEnabled; - -@end diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.m b/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.m deleted file mode 100644 index 25c8fa4..0000000 --- a/WordPress-iOS-Shared/Core/WPTableViewSectionFooterView.m +++ /dev/null @@ -1,105 +0,0 @@ -#import "WPTableViewSectionFooterView.h" -#import "WPTableViewCell.h" -#import "WPStyleGuide.h" -#import "NSString+Util.h" - -@interface WPTableViewSectionFooterView () - -@property (nonatomic, strong) UILabel *titleLabel; - -@end - -CGFloat const WPTableViewSectionFooterViewStandardOffset = 16.0; -CGFloat const WPTableViewSectionFooterViewTopVerticalPadding = 6.0; -CGFloat const WPTableViewSectionFooterViewBottomVerticalPadding = 24.0; - -@implementation WPTableViewSectionFooterView - - -- (instancetype)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - _titleLabel = [[UILabel alloc] init]; - _titleLabel.textAlignment = NSTextAlignmentLeft; - _titleLabel.numberOfLines = 0; - _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; - _titleLabel.font = [WPStyleGuide subtitleFont]; - _titleLabel.textColor = [WPStyleGuide greyDarken10]; - _titleLabel.backgroundColor = [UIColor clearColor]; - _titleLabel.shadowOffset = CGSizeZero; - [self addSubview:_titleLabel]; - - // fixed width should be enabled by default - _fixedWidthEnabled = YES; - } - return self; -} - -- (void)setTitle:(NSString *)title -{ - _title = title; - self.titleLabel.text = _title; - [self setNeedsLayout]; -} - -- (void)setTitleAlignment:(NSTextAlignment)textAlignment -{ - self.titleLabel.textAlignment = textAlignment; -} - -- (NSTextAlignment)titleAlignment -{ - return self.titleLabel.textAlignment; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - - CGFloat sectionWidth = CGRectGetWidth(self.bounds); - CGFloat titleWidth = [[self class] titleLabelWidthFromSectionWidth:sectionWidth fixedWidthEnabled:self.fixedWidthEnabled]; - CGSize titleSize = [[self class] sizeForTitle:self.titleLabel.text andTitleWidth:titleWidth]; - CGFloat padding = (sectionWidth - titleWidth) / 2.0; - - self.titleLabel.frame = CGRectIntegral(CGRectMake(padding, WPTableViewSectionFooterViewTopVerticalPadding, titleWidth, titleSize.height)); -} - -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width -{ - return [self heightForTitle:title andWidth:width fixedWidthEnabled:YES]; -} - -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width fixedWidthEnabled:(BOOL)fixedWidthEnabled -{ - if ([title length] == 0) { - return 0.0; - } - - CGFloat titleWidth = [[self class] titleLabelWidthFromSectionWidth:width fixedWidthEnabled:fixedWidthEnabled]; - return [self sizeForTitle:title andTitleWidth:titleWidth].height + WPTableViewSectionFooterViewTopVerticalPadding + WPTableViewSectionFooterViewBottomVerticalPadding; -} - -#pragma mark - Private Methods - -+ (CGSize)sizeForTitle:(NSString *)title andTitleWidth:(CGFloat)titleWidth -{ - return [title suggestedSizeWithFont:[WPStyleGuide subtitleFont] width:titleWidth]; -} - -+ (CGFloat)titleLabelWidthFromSectionWidth:(CGFloat)sectionWidth fixedWidthEnabled:(BOOL)fixedWidthEnabled -{ - CGFloat titleLabelWidth = sectionWidth; - CGFloat fixedWidth = [[self class] fixedWidth]; - if (fixedWidthEnabled && fixedWidth > 0) { - titleLabelWidth = MIN(fixedWidth, titleLabelWidth); - } - return titleLabelWidth - (2 * WPTableViewSectionFooterViewStandardOffset); -} - -+ (CGFloat)fixedWidth -{ - return IS_IPAD ? WPTableViewFixedWidth : 0.0; -} - -@end diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.h b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.h new file mode 100644 index 0000000..ee430ec --- /dev/null +++ b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.h @@ -0,0 +1,72 @@ +#import + + + +/** + * @enum WPTableViewSectionStyle + * @brief The WPTableViewSectionHeaderFooterView helper class has two default styles: Header and Footer. + * By means of this simple enum, we'll be able to initialize the HeaderFooterView with the + * standard styles that should be applied when using this tool as a Header, or a Footer. + */ + +typedef NS_ENUM(NSInteger, WPTableViewSectionStyle) +{ + WPTableViewSectionStyleHeader, + WPTableViewSectionStyleFooter +}; + + + +/** + * @class WPTableViewSectionHeaderFooterView + * @brief This class is meant to be used as TableView Section Footer, and provides a custom style that + * should be used app-wide. + */ + +@interface WPTableViewSectionHeaderFooterView : UITableViewHeaderFooterView + +@property (nonatomic, assign, readonly) WPTableViewSectionStyle style; +@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) UIColor *titleColor; +@property (nonatomic, strong) UIFont *titleFont; +@property (nonatomic, assign) NSTextAlignment titleAlignment; +@property (nonatomic, assign) UIEdgeInsets titleInsets; +@property (nonatomic, assign) BOOL uppercase; + +- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier style:(WPTableViewSectionStyle)style; + + +/** + * @brief Calculates the Height required to display a View with the default Header Styles. + * + * @param headerText The text to be rendered. + * @param width The container's width. + * @returns Required Height + */ + ++ (CGFloat)heightForHeader:(NSString *)headerText width:(CGFloat)width; + + +/** + * @brief Calculates the Height required to display a View with the default Footer Styles. + * + * @param headerText The text to be rendered. + * @param width The container's width. + * @returns Required Height + */ + ++ (CGFloat)heightForFooter:(NSString *)footerText width:(CGFloat)width; + + +/** + * @brief Calculates the Height required to display a View with a custom Font and Title Insets. + * + * @param text The text to be rendered. + * @param width The container's width. + * @param font The font that should be used. + * @returns Required Height + */ + ++ (CGFloat)heightForText:(NSString *)text width:(CGFloat)width titleInsets:(UIEdgeInsets)titleInsets font:(UIFont *)font; + +@end diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.m b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.m new file mode 100644 index 0000000..672d985 --- /dev/null +++ b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderFooterView.m @@ -0,0 +1,241 @@ +#import "WPTableViewSectionHeaderFooterView.h" +#import "WPTableViewCell.h" +#import "WPStyleGuide.h" +#import "NSString+Util.h" + + + +@interface WPTableViewSectionHeaderFooterView () +@property (nonatomic, strong) UILabel *titleLabel; +@end + + +@implementation WPTableViewSectionHeaderFooterView + +- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier +{ + return [self initWithReuseIdentifier:reuseIdentifier style:WPTableViewSectionStyleHeader]; +} + +- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier style:(WPTableViewSectionStyle)style +{ + NSParameterAssert(style == WPTableViewSectionStyleHeader || style == WPTableViewSectionStyleFooter); + + self = [super initWithReuseIdentifier:reuseIdentifier]; + if (self) { + _style = style; + [self setupSubviews]; + } + return self; +} + +- (void)setupSubviews +{ + BOOL isHeader = self.style == WPTableViewSectionStyleHeader; + + UIEdgeInsets titleInsets = isHeader ? [[self class] headerTitleInsets] : [[self class] footerTitleInsets]; + UIColor *titleColor = isHeader ? [[self class] headerTitleColor] : [[self class] footerTitleColor]; + UIFont *titleFont = isHeader ? [[self class] headerTitleFont] : [[self class] footerTitleFont]; + + // Title Label + UILabel *titleLabel = [UILabel new]; + titleLabel.textAlignment = NSTextAlignmentLeft; + titleLabel.numberOfLines = 0; + titleLabel.lineBreakMode = NSLineBreakByWordWrapping; + titleLabel.font = titleFont; + titleLabel.textColor = titleColor; + titleLabel.backgroundColor = [UIColor clearColor]; + titleLabel.shadowOffset = CGSizeZero; + [self addSubview:titleLabel]; + + // Background + UIView *backgroundView = [UIView new]; + backgroundView.backgroundColor = [UIColor clearColor]; + + // Initialize Prperties + _uppercase = isHeader; + _titleLabel = titleLabel; + _titleInsets = titleInsets; + self.backgroundView = backgroundView; + + // Make sure this view is laid ut + [self setNeedsLayout]; +} + + + +#pragma mark - Overriden Properties + +/** + Note: + The purpose of the following overrides are to prevent UI glitches, caused by users accessing the + default textLabel and detailTextLabel provided by the superclass. + We're effectively disabling those fields! + */ + +- (UILabel *)textLabel +{ + return nil; +} + +- (UILabel *)detailTextLabel +{ + return nil; +} + + + +#pragma mark - Properties + +- (NSString *)title +{ + return self.titleLabel.text; +} + +- (void)setTitle:(NSString *)title +{ + self.titleLabel.text = self.uppercase ? [title uppercaseStringWithLocale:[NSLocale currentLocale]] : title; + [self setNeedsLayout]; +} + +- (UIColor *)titleColor +{ + return self.titleLabel.textColor; +} + +- (void)setTitleColor:(UIColor *)color +{ + self.titleLabel.textColor = color; +} + +- (UIFont *)titleFont +{ + return self.titleLabel.font; +} + +- (void)setTitleFont:(UIFont *)titleFont +{ + self.titleLabel.font = titleFont; + [self setNeedsLayout]; +} + +- (void)setTitleAlignment:(NSTextAlignment)textAlignment +{ + self.titleLabel.textAlignment = textAlignment; +} + +- (NSTextAlignment)titleAlignment +{ + return self.titleLabel.textAlignment; +} + +- (void)setTitleInsets:(UIEdgeInsets)titleInsets +{ + _titleInsets = titleInsets; + [self setNeedsLayout]; +} + +- (void)setUppercase:(BOOL)uppercase +{ + _uppercase = uppercase; + [self setNeedsLayout]; +} + + + +#pragma mark - Layout + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + CGFloat sectionWidth = CGRectGetWidth(self.bounds); + CGFloat titleWidth = [[self class] titleLabelWidthFromSectionWidth:sectionWidth titleInsets:self.titleInsets]; + CGSize titleSize = [[self class] sizeForTitle:self.titleLabel.text titleWidth:titleWidth font:self.titleFont]; + CGFloat padding = (sectionWidth - titleWidth) * 0.5; + + self.titleLabel.frame = CGRectIntegral(CGRectMake(padding, self.titleInsets.top, titleWidth, titleSize.height)); +} + + + +#pragma mark - Public Static Helpers + ++ (CGFloat)heightForHeader:(NSString *)headerText width:(CGFloat)width +{ + return [self heightForText:headerText width:width titleInsets:[self headerTitleInsets] font:[self headerTitleFont]]; +} + ++ (CGFloat)heightForFooter:(NSString *)footerText width:(CGFloat)width +{ + return [self heightForText:footerText width:width titleInsets:[self footerTitleInsets] font:[self footerTitleFont]]; +} + ++ (CGFloat)heightForText:(NSString *)text width:(CGFloat)width titleInsets:(UIEdgeInsets)titleInsets font:(UIFont *)font +{ + if (text.length == 0) { + return 0.0; + } + + CGFloat titleWidth = [self titleLabelWidthFromSectionWidth:width titleInsets:titleInsets]; + CGSize titleSize = [self sizeForTitle:text titleWidth:titleWidth font:font]; + + return titleSize.height + titleInsets.top + titleInsets.bottom; +} + + + +#pragma mark - Private Methods + ++ (CGSize)sizeForTitle:(NSString *)title titleWidth:(CGFloat)titleWidth font:(UIFont *)font +{ + return [title suggestedSizeWithFont:font width:titleWidth]; +} + ++ (CGFloat)titleLabelWidthFromSectionWidth:(CGFloat)sectionWidth titleInsets:(UIEdgeInsets)titleInsets +{ + CGFloat fixedWidth = self.fixedWidth; + CGFloat titleLabelWidth = (fixedWidth > 0) ? MIN(fixedWidth, sectionWidth) : sectionWidth; + + return titleLabelWidth - titleInsets.left - titleInsets.right; +} + ++ (CGFloat)fixedWidth +{ + return IS_IPAD ? WPTableViewFixedWidth : 0.0; +} + + +#pragma mark - Defaults + ++ (UIEdgeInsets)headerTitleInsets +{ + return UIEdgeInsetsMake(21.0, 16.0, 8.0, 16.0); +} + ++ (UIEdgeInsets)footerTitleInsets +{ + return UIEdgeInsetsMake(6.0, 16.0, 24.0, 16.0); +} + ++ (UIColor *)headerTitleColor +{ + return [WPStyleGuide whisperGrey]; +} + ++ (UIColor *)footerTitleColor +{ + return [WPStyleGuide greyDarken10]; +} + ++ (UIFont *)headerTitleFont +{ + return [WPStyleGuide tableviewSectionHeaderFont]; +} + ++ (UIFont *)footerTitleFont +{ + return [WPStyleGuide subtitleFont]; +} + +@end diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.h b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.h deleted file mode 100644 index 2d8644a..0000000 --- a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.h +++ /dev/null @@ -1,21 +0,0 @@ -#import - -@interface WPTableViewSectionHeaderView : UIView - -@property (nonatomic, strong) NSString *title; - -// By default, fixedWidth will be enabled, which means for iPads -// the title label width will be <= WPTableViewFixedWidth. There -// will be equal padding before and after the label, if you want the label -// to have a default padding and a full width instead, you can disable the fixedWidth flag. -@property (nonatomic) BOOL fixedWidthEnabled; - -// By default, fixedWidth flag will assumed to be enabled and the title label width -// will be treated for <= WPTableViewFixedWidth for iPads. -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width; - -// If you disable the fixedWidth flag for the instance, you should pass `NO` as the -// fixedWidthEnabled parameter, so it will use the full width for the calculation -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width fixedWidthEnabled:(BOOL)fixedWidthEnabled; - -@end diff --git a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.m b/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.m deleted file mode 100644 index 8462332..0000000 --- a/WordPress-iOS-Shared/Core/WPTableViewSectionHeaderView.m +++ /dev/null @@ -1,98 +0,0 @@ -#import "WPTableViewSectionHeaderView.h" -#import "WPTableViewCell.h" -#import "WPStyleGuide.h" -#import "NSString+Util.h" - -@interface WPTableViewSectionHeaderView () - -@property (nonatomic, strong) UILabel *titleLabel; - -@end - -CGFloat const WPTableViewSectionHeaderViewStandardOffset = 16.0; -CGFloat const WPTableViewSectionHeaderViewTopVerticalPadding = 21.0; -CGFloat const WPTableViewSectionHeaderViewBottomVerticalPadding = 8.0; - -@implementation WPTableViewSectionHeaderView - -- (id)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - _titleLabel = [[UILabel alloc] init]; - _titleLabel.textAlignment = NSTextAlignmentLeft; - _titleLabel.numberOfLines = 0; - _titleLabel.lineBreakMode = NSLineBreakByWordWrapping; - _titleLabel.font = [WPStyleGuide tableviewSectionHeaderFont]; - _titleLabel.textColor = [WPStyleGuide whisperGrey]; - _titleLabel.backgroundColor = [UIColor clearColor]; - _titleLabel.shadowOffset = CGSizeMake(0.0, 0.0); - [self addSubview:_titleLabel]; - - // fixed width should be enabled by default - _fixedWidthEnabled = YES; - } - return self; -} - -- (void)setTitle:(NSString *)title -{ - _title = [title uppercaseStringWithLocale:[NSLocale currentLocale]]; - self.titleLabel.text = _title; - [self setNeedsLayout]; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - - CGFloat sectionWidth = CGRectGetWidth(self.bounds); - CGFloat titleWidth = [[self class] titleLabelWidthFromSectionWidth:sectionWidth fixedWidthEnabled:self.fixedWidthEnabled]; - CGSize titleSize = [[self class] sizeForTitle:self.titleLabel.text andTitleWidth:titleWidth]; - CGFloat padding = (sectionWidth - titleWidth) / 2.0; - - self.titleLabel.frame = CGRectIntegral(CGRectMake(padding, WPTableViewSectionHeaderViewTopVerticalPadding, titleWidth, titleSize.height)); -} - -// fixedWidth is enabled by default -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width -{ - return [self heightForTitle:title andWidth:width fixedWidthEnabled:YES]; -} - -+ (CGFloat)heightForTitle:(NSString *)title andWidth:(CGFloat)width fixedWidthEnabled:(BOOL)fixedWidthEnabled -{ - if ([title length] == 0) { - return 0.0; - } - - CGFloat titleWidth = [[self class] titleLabelWidthFromSectionWidth:width fixedWidthEnabled:fixedWidthEnabled]; - return [self sizeForTitle:title andTitleWidth:titleWidth].height + WPTableViewSectionHeaderViewTopVerticalPadding + WPTableViewSectionHeaderViewBottomVerticalPadding; -} - -#pragma mark - Private Methods - -+ (CGSize)sizeForTitle:(NSString *)title andTitleWidth:(CGFloat)titleWidth -{ - // since we use uppercase title by default, it's important to override it here in case - // this method is called with a lowercase string which would cause a difference in the height calculation - NSString *upppercaseTitle = [title uppercaseStringWithLocale:[NSLocale currentLocale]]; - return [upppercaseTitle suggestedSizeWithFont:[WPStyleGuide tableviewSectionHeaderFont] width:titleWidth]; -} - -+ (CGFloat)titleLabelWidthFromSectionWidth:(CGFloat)sectionWidth fixedWidthEnabled:(BOOL)fixedWidthEnabled -{ - CGFloat titleLabelWidth = sectionWidth; - CGFloat fixedWidth = [[self class] fixedWidth]; - if (fixedWidthEnabled && fixedWidth > 0) { - titleLabelWidth = MIN(fixedWidth, titleLabelWidth); - } - return titleLabelWidth - (2 * WPTableViewSectionHeaderViewStandardOffset); -} - -+ (CGFloat)fixedWidth -{ - return IS_IPAD ? WPTableViewFixedWidth : 0.0; -} - -@end