@@ -14,20 +14,20 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
1414 var titleLable = UILabel ( )
1515 var backView = UIView ( )
1616 let screenW = UIScreen . main. bounds. size. width
17- // let labelGest = UITapGestureRecognizer.init()
17+ let labelGest = UITapGestureRecognizer . init ( )
18+ var locationIndex : Int = 0
1819
1920 override init ( frame: CGRect ) {
2021 super. init ( frame: frame)
2122 titleLable. textColor = UIColor . white
2223 titleLable. font = UIFont . systemFont ( ofSize: 12 )
23- // titleLable.font = UIFont.init(name: "helvetica", size: 12)
2424 titleLable. numberOfLines = 0
2525 titleLable. isUserInteractionEnabled = true
2626 backView. backgroundColor = UIColor . init ( red: 206 / 255.0 , green: 206 / 255.0 , blue: 206 / 255.0 , alpha: 1 )
2727 backView. layer. cornerRadius = 5
2828 backView. clipsToBounds = true
2929 backView. addSubview ( titleLable)
30- // labelGest.addTarget(self, action: #selector(self.clickTapValidation(sender:)))
30+ labelGest. addTarget ( self , action: #selector( self . clickTapValidation ( sender: ) ) )
3131 bubbleView. addSubview ( backView)
3232 }
3333
@@ -56,12 +56,13 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
5656 self . backView. frame = CGRect ( origin: CGPoint ( x: titleX, y: titleY) , size: CGSize ( width: titleSize. width+ 10 , height: titleSize. height+ 10 ) )
5757 self . titleLable. frame = CGRect ( origin: CGPoint ( x: 5 , y: 5 ) , size: CGSize ( width: titleSize. width, height: titleSize. height) )
5858 let attString = NSMutableAttributedString . init ( string: strTitle)
59- // if strTitle.hasSuffix("发送朋友验证"){
60- // self.titleLable.addGestureRecognizer(labelGest)
61- // let tmpArr = rangesOf(searchString: "发送朋友验证", inString: strTitle)
62- // let tmpR:NSRange = tmpArr.lastObject as! NSRange
63- // attString.addAttribute(NSForegroundColorAttributeName, value: UIColor.init(red: 35/255.0, green: 141/255.0, blue: 250/255.0, alpha: 1), range: tmpR)
64- // }
59+ if strTitle. hasSuffix ( " 发送朋友验证 " ) {
60+ self . titleLable. addGestureRecognizer ( labelGest)
61+ let tmpArr = rangesOf ( searchString: " 发送朋友验证 " , inString: strTitle)
62+ let tmpR : NSRange = tmpArr. lastObject as! NSRange
63+ locationIndex = tmpR. location
64+ attString. addAttribute ( NSForegroundColorAttributeName, value: UIColor . init ( red: 35 / 255.0 , green: 141 / 255.0 , blue: 250 / 255.0 , alpha: 1 ) , range: tmpR)
65+ }
6566 self . titleLable. attributedText = attString
6667
6768 }
@@ -93,12 +94,11 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
9394 func clickTapValidation( sender : UITapGestureRecognizer ) {
9495 let touchPoint = sender. location ( in: self . titleLable)
9596 let path : CGMutablePath = CGMutablePath ( )
96- path. addRect ( CGRect ( x: 0 , y: 0 , width: self . titleLable. frame. size. width, height: self . titleLable. frame. size. height) )
97+ path. addRect ( CGRect ( x: 0 , y: 0 , width: self . titleLable. frame. size. width, height: self . titleLable. frame. size. height+ 10 ) )
9798 let framesetter = CTFramesetterCreateWithAttributedString ( self . titleLable. attributedText!)
9899 let ctframe = CTFramesetterCreateFrame ( framesetter, CFRangeMake ( 0 , 0 ) , path, nil )
99100 //获取行数
100101 let lines : NSArray = CTFrameGetLines ( ctframe)
101- print ( " line: \( CFArrayGetCount ( lines) ) line: \( self . titleLable. numberOfLines) height: \( self . titleLable. frame. size. height) " )
102102 let numOfLine : NSInteger = self . titleLable. numberOfLines > 0 ? min ( self . titleLable. numberOfLines, CFArrayGetCount ( lines) ) : CFArrayGetCount ( lines)
103103 if numOfLine != 0 {
104104 var lineOrigins : [ CGPoint ] = Array ( repeating: . zero, count: numOfLine)
@@ -114,7 +114,10 @@ class IMUINotificationMessageCell: IMUIBaseMessageCell {
114114 let lineFrame = CGRect ( x: baseLineOri. x, y: baseLineOri. y- ascent, width: lineWidth, height: ascent+ descent)
115115 if lineFrame. contains ( touchPoint) {
116116 let index = CTLineGetStringIndexForPosition ( line, touchPoint)
117- print ( " index: \( index) " )
117+ if index. hashValue > self . locationIndex {
118+ self . delegate? . messageCollectionView ? ( didTapValidationWithModel: self . message!)
119+ }
120+
118121 }
119122 }
120123 }
0 commit comments