From 0983448c74df271aa861672dd210d3999067e51c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 16 May 2017 12:25:12 -0400 Subject: [PATCH] Add unread indicator. // FREEBIE --- Signal/src/UIView+OWS.h | 11 ++++++ Signal/src/UIView+OWS.m | 41 +++++++++++++++++++++++ Signal/src/views/OWSUnreadIndicatorCell.m | 15 +++------ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Signal/src/UIView+OWS.h b/Signal/src/UIView+OWS.h index c97459ec3..2e31f28d7 100644 --- a/Signal/src/UIView+OWS.h +++ b/Signal/src/UIView+OWS.h @@ -44,6 +44,17 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value); - (void)setCompressionResistanceVerticalLow; - (void)setCompressionResistanceVerticalHigh; +#pragma mark - Manual Layout + +- (CGFloat)left; +- (CGFloat)right; +- (CGFloat)top; +- (CGFloat)bottom; +- (CGFloat)width; +- (CGFloat)height; + +- (void)centerOnSuperview; + #pragma mark - Debugging - (void)addBorderWithColor:(UIColor *)color; diff --git a/Signal/src/UIView+OWS.m b/Signal/src/UIView+OWS.m index 29bd42674..fc60a29ae 100644 --- a/Signal/src/UIView+OWS.m +++ b/Signal/src/UIView+OWS.m @@ -131,6 +131,47 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) [self setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; } +#pragma mark - Manual Layout + +- (CGFloat)left +{ + return self.frame.origin.x; +} + +- (CGFloat)right +{ + return self.frame.origin.x + self.frame.size.width; +} + +- (CGFloat)top +{ + return self.frame.origin.y; +} + +- (CGFloat)bottom +{ + return self.frame.origin.x + self.frame.size.height; +} + +- (CGFloat)width +{ + return self.frame.size.width; +} + +- (CGFloat)height +{ + return self.frame.size.height; +} + +- (void)centerOnSuperview +{ + self.frame = CGRectMake( + round(self.superview.bounds.origin.x + (self.superview.bounds.size.width - self.frame.size.width) * 0.5f), + round(self.superview.bounds.origin.y + (self.superview.bounds.size.height - self.frame.size.height) * 0.5f), + self.frame.size.width, + self.frame.size.height); +} + #pragma mark - Debugging - (void)addBorderWithColor:(UIColor *)color diff --git a/Signal/src/views/OWSUnreadIndicatorCell.m b/Signal/src/views/OWSUnreadIndicatorCell.m index 2971e25e9..0d041dd85 100644 --- a/Signal/src/views/OWSUnreadIndicatorCell.m +++ b/Signal/src/views/OWSUnreadIndicatorCell.m @@ -6,6 +6,7 @@ #import "OWSBezierPathView.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" +#import "UIView+OWS.h" #import @interface OWSUnreadIndicatorCell () @@ -62,16 +63,10 @@ - (void)layoutSubviews { - CGSize labelSize = [self.label sizeThatFits:CGSizeZero]; - self.label.frame = CGRectMake(round(self.bounds.origin.x + (self.bounds.size.width - labelSize.width) * 0.5f), - round(self.bounds.origin.y + (self.bounds.size.height - labelSize.height) * 0.5f), - labelSize.width, - labelSize.height); - self.leftPathView.frame = CGRectMake(0, 0, self.label.frame.origin.x, self.bounds.size.height); - self.rightPathView.frame = CGRectMake(self.label.frame.origin.x + self.label.frame.size.width, - 0, - self.bounds.size.width - (self.label.frame.origin.x + self.label.frame.size.width), - self.bounds.size.height); + [self.label sizeToFit]; + [self.label centerOnSuperview]; + self.leftPathView.frame = CGRectMake(0, 0, self.label.left, self.height); + self.rightPathView.frame = CGRectMake(self.label.right, 0, self.width - self.label.right, self.height); } @end