From 54c56f1c4b160917fc38b2b31639a8d49e8d311a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 23 Oct 2017 13:30:32 -0400 Subject: [PATCH] Fix layout of generic and audio messages. // FREEBIE --- .../Cells/OWSAudioMessageView.m | 3 +- .../Cells/OWSGenericAttachmentView.m | 35 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m index 04a2f1e0a..d9d276cad 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m @@ -217,13 +217,14 @@ NS_ASSUME_NONNULL_BEGIN [self.audioPlayPauseButton autoVCenterInSuperview]; [self.audioPlayPauseButton autoSetDimension:ALDimensionWidth toSize:self.iconSize]; [self.audioPlayPauseButton autoSetDimension:ALDimensionHeight toSize:self.iconSize]; + [self.audioPlayPauseButton setContentHuggingHigh]; const CGFloat kLabelHSpacing = self.audioIconHSpacing; UIView *labelsView = [UIView containerView]; [contentView addSubview:labelsView]; [labelsView autoPinLeadingToTrailingOfView:self.audioPlayPauseButton margin:kLabelHSpacing]; - [labelsView autoPinEdgeToSuperviewEdge:ALEdgeRight]; + [labelsView autoPinTrailingToSuperviewWithMargin:self.audioIconHMargin]; [labelsView autoVCenterInSuperview]; const CGFloat kLabelVSpacing = 2; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m index 2c0d86910..64cb5b9c9 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m @@ -4,6 +4,7 @@ #import "OWSGenericAttachmentView.h" #import "NSString+OWS.h" +#import "OWSBezierPathView.h" #import "UIColor+JSQMessages.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" @@ -116,25 +117,37 @@ NS_ASSUME_NONNULL_BEGIN [contentView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.vMargin]; [contentView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:self.vMargin]; + OWSBezierPathView *iconCircleView = [OWSBezierPathView new]; + UIColor *iconColor + = (self.isIncoming ? [UIColor colorWithRGBHex:0x9e9e9e] : [self foregroundColorWithOpacity:0.15f]); + iconCircleView.configureShapeLayerBlock = ^(CAShapeLayer *_Nonnull layer, CGRect bounds) { + CGFloat radius = MIN(bounds.size.width, bounds.size.height) * 0.5f; + layer.path = [UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:radius].CGPath; + layer.fillColor = iconColor.CGColor; + }; + [contentView addSubview:iconCircleView]; + [iconCircleView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:self.iconHMargin]; + [iconCircleView autoVCenterInSuperview]; + [iconCircleView autoSetDimension:ALDimensionWidth toSize:self.iconSize]; + [iconCircleView autoSetDimension:ALDimensionHeight toSize:self.iconSize]; + [iconCircleView setContentHuggingHigh]; + UIImage *image = [UIImage imageNamed:@"generic-attachment-small"]; OWSAssert(image); UIImageView *imageView = [UIImageView new]; imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageView.tintColor = self.bubbleBackgroundColor; - imageView.backgroundColor - = (self.isIncoming ? [UIColor colorWithRGBHex:0x9e9e9e] : [self foregroundColorWithOpacity:0.15f]); - imageView.layer.cornerRadius = MIN(imageView.bounds.size.width, imageView.bounds.size.height) * 0.5f; [contentView addSubview:imageView]; - [imageView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:self.iconHMargin]; - [imageView autoVCenterInSuperview]; - [imageView autoSetDimension:ALDimensionWidth toSize:self.iconSize]; - [imageView autoSetDimension:ALDimensionHeight toSize:self.iconSize]; + [imageView autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:iconCircleView]; + [imageView autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:iconCircleView]; + [imageView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:iconCircleView]; + [imageView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:iconCircleView]; const CGFloat kLabelHSpacing = self.iconHSpacing; UIView *labelsView = [UIView containerView]; [contentView addSubview:labelsView]; [labelsView autoPinLeadingToTrailingOfView:imageView margin:kLabelHSpacing]; - [labelsView autoPinEdgeToSuperviewEdge:ALEdgeRight]; + [labelsView autoPinTrailingToSuperviewWithMargin:self.iconHMargin]; [labelsView autoVCenterInSuperview]; NSString *filename = self.attachmentStream.sourceFilename; @@ -152,15 +165,15 @@ NS_ASSUME_NONNULL_BEGIN UILabel *fileTypeLabel = [UILabel new]; fileTypeLabel.text = fileExtension.uppercaseString; - fileTypeLabel.textColor = imageView.backgroundColor; + fileTypeLabel.textColor = iconColor; fileTypeLabel.lineBreakMode = NSLineBreakByTruncatingTail; fileTypeLabel.font = [UIFont ows_mediumFontWithSize:20.f]; fileTypeLabel.adjustsFontSizeToFitWidth = YES; fileTypeLabel.textAlignment = NSTextAlignmentCenter; // Center on icon. [imageView addSubview:fileTypeLabel]; - [imageView autoCenterInSuperview]; - [imageView autoSetDimension:ALDimensionWidth toSize:15.f]; + [fileTypeLabel autoCenterInSuperview]; + [fileTypeLabel autoSetDimension:ALDimensionWidth toSize:15.f]; const CGFloat kLabelVSpacing = 2; NSString *topText = [self.attachmentStream.sourceFilename ows_stripped];