Skip to content

Commit 27f2d5c

Browse files
guangyaoguangyao
authored andcommitted
Fix 字体大小问题··位置不正确问题
1 parent 2425041 commit 27f2d5c

File tree

9 files changed

+41
-37
lines changed

9 files changed

+41
-37
lines changed

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Layout/IMUIMessageCellLayout.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ open class IMUIMessageCellLayout: NSObject, IMUIMessageCellLayoutProtocal {
8383
let bubbleHeight = bubbleContentSize.height +
8484
bubbleContentInset.top +
8585
bubbleContentInset.bottom
86-
8786
return CGSize(width: bubbleWidth, height: bubbleHeight)
8887
}
8988

ios/RCTAuroraIMUI/IMUIMessageCollectionView/M80AttributedLabel/M80AttributedLabel/M80AttributedLabel.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,8 @@ - (CGSize)getTheLabelSize:(CGSize)maxSize{
652652
CGFloat tmpH = fitSize.height;
653653
if (tmpW < 30) {
654654
tmpW = 30;
655-
}
656-
if (tmpH < 30) {
657-
tmpH = 15;
655+
}else{
656+
tmpW = tmpW + 3;
658657
}
659658
return CGSizeMake(tmpW, tmpH );
660659
}

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Models/IMUIMessageModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ open class IMUIMessageModel: NSObject, IMUIMessageModelProtocol {
128128
tmpLabel.nim_setText(self.text())
129129
tmpLabel.font = IMUITextMessageCell.inComingTextFont
130130
bubbleContentSize = tmpLabel.getTheLabel(CGSize(width: IMUIMessageCellLayout.bubbleMaxWidth, height: CGFloat(MAXFLOAT)))
131-
131+
// bubbleContentSize = tmpLabel.sizeThatFits(CGSize(width: IMUIMessageCellLayout.bubbleMaxWidth, height: CGFloat(MAXFLOAT)))
132132

133133
// if isOutGoing {
134134
// bubbleContentSize = self.text().sizeWithConstrainedWidth(with: IMUIMessageCellLayout.bubbleMaxWidth, font: IMUITextMessageCell.outGoingTextFont)

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUIBaseMessageCell.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum IMUIMessageCellType {
1717
open class IMUIBaseMessageCell: UICollectionViewCell, IMUIMessageCellProtocal,MenuPopOverViewDelegate {
1818
var bubbleView: IMUIMessageBubbleView
1919
lazy var avatarImage = MyCacheImageView()
20+
lazy var timeBackView = UIView()
2021
lazy var timeLabel = UILabel()
2122
lazy var nameLabel = UILabel()
2223
lazy var durationLabel = UILabel()
@@ -35,7 +36,8 @@ open class IMUIBaseMessageCell: UICollectionViewCell, IMUIMessageCellProtocal,Me
3536

3637
self.contentView.addSubview(self.bubbleView)
3738
self.contentView.addSubview(self.avatarImage)
38-
self.contentView.addSubview(self.timeLabel)
39+
self.contentView.addSubview(self.timeBackView)
40+
self.timeBackView.addSubview(self.timeLabel)
3941
self.contentView.addSubview(self.nameLabel)
4042
self.contentView.addSubview(self.durationLabel)
4143
self.contentView.addSubview(self.isPlayedView)
@@ -72,17 +74,18 @@ open class IMUIBaseMessageCell: UICollectionViewCell, IMUIMessageCellProtocal,Me
7274
timeLabel.textAlignment = .center
7375
timeLabel.textColor = UIColor.white
7476
timeLabel.font = IMUIMessageCellLayout.timeStringFont
75-
timeLabel.backgroundColor = UIColor.init(red: 206/255.0, green: 206/255.0, blue: 206/255.0, alpha: 1)
76-
timeLabel.layer.cornerRadius = 5
77-
timeLabel.clipsToBounds = true
77+
timeBackView.backgroundColor = UIColor.init(red: 206/255.0, green: 206/255.0, blue: 206/255.0, alpha: 1)
78+
timeBackView.layer.cornerRadius = 5
79+
timeBackView.clipsToBounds = true
7880
}
7981

8082
required public init?(coder aDecoder: NSCoder) {
8183
fatalError("init(coder:) has not been implemented")
8284
}
8385

8486
func layoutCell(with layout: IMUIMessageCellLayoutProtocal, viewCache: IMUIReuseViewCache) {
85-
self.timeLabel.frame = layout.timeLabelFrame
87+
self.timeBackView.frame = layout.timeLabelFrame
88+
self.timeLabel.frame = self.timeBackView.bounds
8689
self.avatarImage.frame = layout.avatarFrame
8790
self.avatarImage.layer.cornerRadius = 5.0;
8891
self.avatarImage.layer.masksToBounds = true;
@@ -127,14 +130,15 @@ open class IMUIBaseMessageCell: UICollectionViewCell, IMUIMessageCellProtocal,Me
127130
func setupData(with message: IMUIMessageModelProtocol) {
128131
// self.avatarImage.image = message.fromUser.Avatar()
129132
self.avatarImage.setImageURL(message.fromUser.Avatar())
130-
self.bubbleView.backgroundColor = UIColor.init(netHex: 0xE7EBEF)
133+
self.bubbleView.backgroundColor = UIColor.clear
131134
self.timeLabel.text = message.timeString
132135
let timeW = widthWithFont(font: IMUIMessageCellLayout.timeStringFont, text: message.timeString)
133136
let timeX = (UIScreen.main.bounds.size.width - timeW)*0.5
134-
var timeRect = self.timeLabel.frame;
137+
var timeRect = self.timeBackView.frame;
135138
timeRect.size.width = timeW
136139
timeRect.origin.x = timeX
137-
self.timeLabel.frame = timeRect
140+
self.timeBackView.frame = timeRect
141+
self.timeLabel.frame = self.timeBackView.bounds
138142
self.nameLabel.text = message.fromUser.displayName()
139143

140144
self.message = message

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUIImageMessageCell.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class IMUIImageMessageCell: IMUIBaseMessageCell {
3131
let layout = message.layout
3232
self.imageView.frame = UIEdgeInsetsInsetRect(CGRect(origin: CGPoint.zero, size: layout.bubbleFrame.size), layout.bubbleContentInset)
3333
let image = UIImage(contentsOfFile: message.mediaFilePath())
34-
self.layoutImage(image: image!)
34+
if image != nil {
35+
self.layoutImage(image: image!)
36+
}
37+
3538
}
3639

3740
func layoutImage(image: UIImage) {

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUINotificationMessageCell.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ import UIKit
1212
class IMUINotificationMessageCell: IMUIBaseMessageCell {
1313

1414
var titleLable = UILabel()
15+
var backView = UIView()
1516
let screenW = UIScreen.main.bounds.size.width
1617

1718
override init(frame: CGRect) {
1819
super.init(frame: frame)
1920
titleLable.textColor = UIColor.white
2021
titleLable.font = UIFont.systemFont(ofSize: 12)
2122
titleLable.textAlignment = NSTextAlignment.center
22-
titleLable.backgroundColor = UIColor.init(red: 206/255.0, green: 206/255.0, blue: 206/255.0, alpha: 1)
23-
titleLable.layer.cornerRadius = 5
24-
titleLable.clipsToBounds = true
25-
bubbleView.addSubview(titleLable)
23+
backView.backgroundColor = UIColor.init(red: 206/255.0, green: 206/255.0, blue: 206/255.0, alpha: 1)
24+
backView.layer.cornerRadius = 5
25+
backView.clipsToBounds = true
26+
backView.addSubview(titleLable)
27+
bubbleView.addSubview(backView)
2628
}
2729

2830
required init?(coder aDecoder: NSCoder) {
@@ -42,7 +44,8 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
4244
let titleSize = sizeWithFont(font: UIFont.systemFont(ofSize: 12), text: strTitle, maxWidth: layout.bubbleFrame.size.width*0.8)
4345
let titleX = (layout.bubbleFrame.size.width - titleSize.width - 10) * 0.5
4446
let titleY = (layout.bubbleFrame.size.height - titleSize.height - 10) * 0.3
45-
self.titleLable.frame = CGRect(origin: CGPoint(x:titleX, y:titleY), size: CGSize(width:titleSize.width+10, height:titleSize.height+10))
47+
self.backView.frame = CGRect(origin: CGPoint(x:titleX, y:titleY), size: CGSize(width:titleSize.width+10, height:titleSize.height+10));
48+
self.titleLable.frame = self.backView.bounds
4649

4750
}
4851
func sizeWithFont(font : UIFont, text : String, maxWidth: CGFloat) -> CGSize {

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUIRedPacketMessageCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IMUIRedPacketMessageCell: IMUIBaseMessageCell {
1919
override init(frame: CGRect) {
2020
super.init(frame: frame)
2121
backgroundImg.image = UIImage.init(named: "redPacket")
22-
backgroundImg.contentMode = UIViewContentMode.scaleToFill
22+
backgroundImg.contentMode = UIViewContentMode.scaleAspectFill
2323
contentLable.textColor = UIColor.white
2424
contentLable.font = UIFont.systemFont(ofSize: (screenW * 15 / 375))
2525
tipsLabel.textColor = UIColor.white
@@ -52,7 +52,7 @@ class IMUIRedPacketMessageCell: IMUIBaseMessageCell {
5252
let strTitle = tmpDict.object(forKey: "comments") as! String
5353
contentLable.text = strTitle
5454

55-
self.backgroundImg.frame = UIEdgeInsetsInsetRect(CGRect(origin: CGPoint.zero, size: layout.bubbleFrame.size), layout.bubbleContentInset)
55+
self.backgroundImg.frame = CGRect(origin: CGPoint.zero, size: layout.bubbleFrame.size)
5656
let contentX = layout.bubbleFrame.size.width * 0.26
5757
let contentW = layout.bubbleFrame.size.width * 0.7
5858
let contentH = layout.bubbleFrame.size.height * 0.74

ios/RCTAuroraIMUI/IMUIMessageCollectionView/Views/IMUITextMessageCell.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ open class IMUITextMessageCell: IMUIBaseMessageCell {
1414
open static var inComingTextColor = UIColor.white
1515
open static let screenW = UIScreen.main.bounds.size.width
1616

17-
open static var outGoingTextFont = UIFont.systemFont(ofSize: (screenW * 16 / 375))
18-
open static var inComingTextFont = UIFont.systemFont(ofSize: (screenW * 16 / 375))
17+
open static var outGoingTextFont = screenW<375 ? UIFont.systemFont(ofSize:15) : UIFont.systemFont(ofSize: (screenW * 16 / 375))
18+
open static var inComingTextFont = screenW<375 ? UIFont.systemFont(ofSize:15) : UIFont.systemFont(ofSize: (screenW * 16 / 375))
1919

2020
// var textMessageLable = IMUITextView()
2121
var textMessageLable = M80AttributedLabel()
@@ -48,21 +48,17 @@ open class IMUITextMessageCell: IMUIBaseMessageCell {
4848
super.presentCell(with: message, viewCache: viewCache, delegate: delegate)
4949

5050
let layout = message.layout
51-
52-
var tmpContentInset = layout.bubbleContentInset
53-
if layout.bubbleFrame.size.height > 50 {
54-
tmpContentInset.left = message.isOutGoing ? 5 : 15
55-
tmpContentInset.right = message.isOutGoing ? 10 : 5
51+
self.layoutToText(with: message.text(), isOutGoing: message.isOutGoing)
52+
if (layout.bubbleFrame.size.height/21) > 1 {
5653
self.textMessageLable.textAlignment = CTTextAlignment.left
5754
}else{
58-
tmpContentInset.left = message.isOutGoing ? 0 : 5
59-
tmpContentInset.right = message.isOutGoing ? 5 : 0
6055
self.textMessageLable.textAlignment = CTTextAlignment.center
6156
}
62-
tmpContentInset.top = 6
63-
tmpContentInset.bottom = 0
64-
self.textMessageLable.frame = UIEdgeInsetsInsetRect(CGRect(origin: CGPoint.zero, size: layout.bubbleFrame.size), tmpContentInset)
65-
self.layoutToText(with: message.text(), isOutGoing: message.isOutGoing)
57+
let textX = layout.bubbleContentInset.left
58+
let textY = layout.bubbleContentInset.top
59+
let textSize = self.textMessageLable.getTheLabel(CGSize(width: IMUIMessageCellLayout.bubbleMaxWidth, height: CGFloat(MAXFLOAT)))
60+
self.textMessageLable.frame = CGRect(origin: CGPoint(x:textX, y:textY), size: textSize)
61+
6662
}
6763

6864

ios/RCTAuroraIMUI/MyMessageModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ open class RCTMessageModel: IMUIMessageModel {
409409

410410
//MARK - IMUIMessageCellLayoutProtocal
411411
open class MyMessageCellLayout: IMUIMessageCellLayout {
412-
open static var outgoingPadding = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 15)
413-
open static var incommingPadding = UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 10)
412+
open static var outgoingPadding = UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 15)
413+
open static var incommingPadding = UIEdgeInsets(top: 5, left: 15, bottom: 5, right: 10)
414414

415415
override init(isOutGoingMessage: Bool, isNeedShowTime: Bool, bubbleContentSize: CGSize, bubbleContentInsets: UIEdgeInsets, showAvatar: Bool) {
416416

@@ -422,7 +422,7 @@ open class MyMessageCellLayout: IMUIMessageCellLayout {
422422
if isOutGoingMessage {
423423
return MyMessageCellLayout.outgoingPadding
424424
} else {
425-
return MyMessageCellLayout.outgoingPadding
425+
return MyMessageCellLayout.incommingPadding
426426
}
427427
}
428428

0 commit comments

Comments
 (0)