System messsages can show timestamp

added the JSQCollectionViewCell cellTopLabel to the system message
layout

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent c952036075
commit 1125e2ac99

@ -1723,6 +1723,9 @@ typedef enum : NSUInteger {
[self.collectionView dequeueReusableCellWithReuseIdentifier:[OWSSystemMessageCell cellReuseIdentifier]
forIndexPath:indexPath];
[cell configureWithInteraction:interaction];
cell.cellTopLabel.attributedText =
[self collectionView:self.collectionView attributedTextForCellTopLabelAtIndexPath:indexPath];
cell.systemMessageCellDelegate = self;
return cell;

@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UIImageView *imageView;
@property (nonatomic) UILabel *titleLabel;
@property (nonatomic) UILabel *cellTopLabel;
@end
@ -31,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSSystemMessageCell
// override from JSQMessagesCollectionViewCell
@synthesize cellTopLabel = _cellTopLabel;
// `[UIView init]` invokes `[self initWithFrame:...]`.
- (instancetype)initWithFrame:(CGRect)frame
{
@ -49,6 +53,12 @@ NS_ASSUME_NONNULL_BEGIN
self.backgroundColor = [UIColor whiteColor];
self.cellTopLabel = [UILabel new];
self.cellTopLabel.textAlignment = NSTextAlignmentCenter;
self.cellTopLabel.font = self.topLabelFont;
self.cellTopLabel.textColor = [UIColor lightGrayColor];
[self.contentView addSubview:self.cellTopLabel];
self.imageView = [UIImageView new];
[self.contentView addSubview:self.imageView];
@ -84,6 +94,11 @@ NS_ASSUME_NONNULL_BEGIN
[self setNeedsLayout];
}
- (UIFont *)topLabelFont
{
return [UIFont boldSystemFontOfSize:12.0f];
}
- (UIColor *)textColor
{
return [UIColor colorWithRGBHex:0x303030];
@ -227,6 +242,12 @@ NS_ASSUME_NONNULL_BEGIN
return 20.f;
}
/// The default layout spacing for the top label (e.g. timestamp) feels a little too close for the system messages.
- (CGFloat)topLabelBottomMargin
{
return 4.f;
}
- (void)layoutSubviews
{
[super layoutSubviews];
@ -235,12 +256,19 @@ NS_ASSUME_NONNULL_BEGIN
CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)];
CGFloat contentWidth = ([self iconSize] + [self hSpacing] + titleSize.width);
CGSize topLabelSize = [self.cellTopLabel sizeThatFits:CGSizeMake(self.contentView.width, CGFLOAT_MAX)];
self.cellTopLabel.frame = CGRectMake(0, 0, self.contentView.frame.size.width, topLabelSize.height);
CGFloat topLabelSpacing = topLabelSize.height + [self topLabelBottomMargin];
self.imageView.frame = CGRectMake(round((self.contentView.width - contentWidth) * 0.5f),
round((self.contentView.height - [self iconSize]) * 0.5f),
round((self.contentView.height - [self iconSize] + topLabelSpacing) * 0.5f),
[self iconSize],
[self iconSize]);
self.titleLabel.frame = CGRectMake(round(self.imageView.right + [self hSpacing]),
round((self.contentView.height - titleSize.height) * 0.5f),
round((self.contentView.height - titleSize.height + topLabelSpacing) * 0.5f),
ceil(titleSize.width + 1.f),
ceil(titleSize.height + 1.f));
}
@ -254,9 +282,12 @@ NS_ASSUME_NONNULL_BEGIN
[self applyTitleForInteraction:interaction label:self.titleLabel];
CGFloat maxTitleWidth = (collectionViewWidth - ([self hMargin] * 2.f + [self hSpacing] + [self iconSize]));
CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)];
CGFloat contentHeight = ceil(MAX([self iconSize], titleSize.height));
result.height += contentHeight;
result.height += [self topLabelBottomMargin];
return result;
}

Loading…
Cancel
Save