From 78fc068a5ff02550cb86f19f9be8617ab77fa928 Mon Sep 17 00:00:00 2001 From: kevinzhow Date: Fri, 1 May 2015 17:08:03 +0800 Subject: [PATCH] Fix min cell width --- Yep/Info.plist | 2 +- Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.swift | 5 +++++ Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.xib | 6 +++--- Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift | 9 +++++++-- .../Cells/ChatRightAudio/ChatRightAudioCell.swift | 7 +++++++ Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.xib | 6 +++--- Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift | 10 +++++++++- 7 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Yep/Info.plist b/Yep/Info.plist index 188c74c6..b2b2821c 100644 --- a/Yep/Info.plist +++ b/Yep/Info.plist @@ -19,7 +19,7 @@ CFBundleSignature ???? CFBundleVersion - 3 + 5 LSRequiresIPhoneOS NSLocationWhenInUseUsageDescription diff --git a/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.swift b/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.swift index 1354b043..c7c7bee3 100644 --- a/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.swift +++ b/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.swift @@ -83,6 +83,11 @@ class ChatLeftAudioCell: UICollectionViewCell { if let audioSamples = metaDataDict["audio_samples"] as? [CGFloat] { sampleViewWidthConstraint.constant = CGFloat(audioSamples.count) * (YepConfig.audioSampleWidth() + YepConfig.audioSampleGap()) - YepConfig.audioSampleGap() // 最后最后一个 gap 不要 + + if sampleViewWidthConstraint.constant < minSampleViewWidth { + sampleViewWidthConstraint.constant = minSampleViewWidth + } + sampleView.samples = audioSamples if let audioDuration = metaDataDict["audio_duration"] as? Double { diff --git a/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.xib b/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.xib index 7330348a..02ec8e8c 100644 --- a/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.xib +++ b/Yep/Views/Cells/ChatLeftAudio/ChatLeftAudioCell.xib @@ -1,7 +1,7 @@ - + - + @@ -91,7 +91,7 @@ - + diff --git a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift index 76950d43..0a5f72fa 100644 --- a/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift +++ b/Yep/Views/Cells/ChatLeftText/ChatLeftTextCell.swift @@ -29,6 +29,7 @@ class ChatLeftTextCell: UICollectionViewCell { avatarImageViewWidthConstraint.constant = YepConfig.chatCellAvatarSize() textContentLabel.font = UIFont.chatTextFont() + textContentLabel.textAlignment = NSTextAlignment.Center textContentLabelLeadingConstaint.constant = YepConfig.chatCellGapBetweenTextContentLabelAndAvatar() textContentLabelTrailingConstraint.constant = YepConfig.chatTextGapBetweenWallAndContentLabel() @@ -38,8 +39,12 @@ class ChatLeftTextCell: UICollectionViewCell { func configureWithMessage(message: Message, textContentLabelWidth: CGFloat) { textContentLabel.text = message.textContent - - textContentLabelWidthConstraint.constant = textContentLabelWidth + + if textContentLabelWidth < minTextLabelWidth { + textContentLabelWidthConstraint.constant = minTextLabelWidth + }else{ + textContentLabelWidthConstraint.constant = textContentLabelWidth + } if let sender = message.fromFriend { AvatarCache.sharedInstance.roundAvatarOfUser(sender, withRadius: YepConfig.chatCellAvatarSize() * 0.5) { roundImage in diff --git a/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.swift b/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.swift index 5db738ce..d4d026b3 100644 --- a/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.swift +++ b/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.swift @@ -8,6 +8,8 @@ import UIKit +let minSampleViewWidth: CGFloat = 25.0 + class ChatRightAudioCell: UICollectionViewCell { var message: Message! @@ -81,6 +83,11 @@ class ChatRightAudioCell: UICollectionViewCell { if let audioSamples = metaDataDict["audio_samples"] as? [CGFloat] { sampleViewWidthConstraint.constant = CGFloat(audioSamples.count) * (YepConfig.audioSampleWidth() + YepConfig.audioSampleGap()) - YepConfig.audioSampleGap() // 最后最后一个 gap 不要 + + if sampleViewWidthConstraint.constant < minSampleViewWidth { + sampleViewWidthConstraint.constant = minSampleViewWidth + } + sampleView.samples = audioSamples if let audioDuration = metaDataDict["audio_duration"] as? Double { diff --git a/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.xib b/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.xib index a98c4806..95eb9c43 100644 --- a/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.xib +++ b/Yep/Views/Cells/ChatRightAudio/ChatRightAudioCell.xib @@ -1,7 +1,7 @@ - + - + @@ -92,7 +92,7 @@ - + diff --git a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift index 5ea8ac39..19462975 100644 --- a/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift +++ b/Yep/Views/Cells/ChatRightText/ChatRightTextCell.swift @@ -8,6 +8,8 @@ import UIKit +let minTextLabelWidth: CGFloat = 20.0 + class ChatRightTextCell: UICollectionViewCell { @IBOutlet weak var avatarImageView: UIImageView! @@ -29,6 +31,7 @@ class ChatRightTextCell: UICollectionViewCell { avatarImageViewTrailingConstraint.constant = YepConfig.chatCellGapBetweenWallAndAvatar() textContentLabel.font = UIFont.chatTextFont() + textContentLabel.textAlignment = NSTextAlignment.Center textContentLabelTrailingConstraint.constant = YepConfig.chatCellGapBetweenTextContentLabelAndAvatar() textContentLabelLeadingConstraint.constant = YepConfig.chatTextGapBetweenWallAndContentLabel() @@ -41,7 +44,12 @@ class ChatRightTextCell: UICollectionViewCell { func configureWithMessage(message: Message, textContentLabelWidth: CGFloat) { textContentLabel.text = message.textContent - textContentLabelWidthConstraint.constant = textContentLabelWidth + if textContentLabelWidth < minTextLabelWidth { + textContentLabelWidthConstraint.constant = minTextLabelWidth + }else{ + textContentLabelWidthConstraint.constant = textContentLabelWidth + } + if let sender = message.fromFriend { AvatarCache.sharedInstance.roundAvatarOfUser(sender, withRadius: YepConfig.chatCellAvatarSize() * 0.5) { roundImage in