Skip to content

Commit f353648

Browse files
committed
Add the rich text display text message.
fix xhzengAIB#43
1 parent e52c48b commit f353648

38 files changed

Lines changed: 4842 additions & 49 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Xcode
77
#
88
build/
9+
*.xcuserstate
10+
*.xcbkptlist
911
*.pbxuser
1012
!default.pbxuser
1113
*.mode1v3

Example/MessageDisplayExample/MessageDisplayExample.xcodeproj/project.pbxproj

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.

Example/MessageDisplayExample/MessageDisplayExample/XHDemoWeChatMessageTableViewController.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ @interface XHDemoWeChatMessageTableViewController ()
2323
@implementation XHDemoWeChatMessageTableViewController
2424

2525
- (XHMessage *)getTextMessageWithBubbleMessageType:(XHBubbleMessageType)bubbleMessageType {
26-
XHMessage *textMessage = [[XHMessage alloc] initWithText:@"这是华捷微信,为什么模仿这个页面效果呢?希望微信团队能看到我们在努力,请微信团队给个机会,让我好好的努力靠近大神,希望自己也能发亮,好像有点过分的希望了,如果大家喜欢这个开源库,请大家帮帮忙支持这个开源库吧!我是Jack,叫华仔也行,曾宪华就是我啦!Call Me 15915895880" sender:@"华仔" timestamp:[NSDate distantPast]];
26+
XHMessage *textMessage = [[XHMessage alloc] initWithText:@"Call Me 15915895880.这是华捷微信,为什么模仿这个页面效果呢?希望微信团队能看到我们在努力,请微信团队给个机会,让我好好的努力靠近大神,希望自己也能发亮,好像有点过分的希望了,如果大家喜欢这个开源库,请大家帮帮忙支持这个开源库吧!我是Jack,叫华仔也行,曾宪华就是我啦!" sender:@"华仔" timestamp:[NSDate distantPast]];
2727
textMessage.avator = [UIImage imageNamed:@"avator"];
2828
textMessage.avatorUrl = @"http://www.pailixiu.com/jack/meIcon@2x.png";
2929
textMessage.bubbleMessageType = bubbleMessageType;
@@ -99,15 +99,15 @@ - (void)loadDemoDataSource {
9999
[messages addObject:[self getTextMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
100100
[messages addObject:[self getTextMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
101101

102-
[messages addObject:[self getPhotoMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
102+
[messages addObject:[self getPhotoMessageWithBubbleMessageType:(i % 5) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
103103

104-
[messages addObject:[self getVideoMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
104+
[messages addObject:[self getVideoMessageWithBubbleMessageType:(i % 6) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
105105

106-
[messages addObject:[self getVoiceMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
106+
[messages addObject:[self getVoiceMessageWithBubbleMessageType:(i % 4) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
107107

108108
[messages addObject:[self getEmotionMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
109109

110-
[messages addObject:[self getGeolocationsMessageWithBubbleMessageType:(i % 2) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
110+
[messages addObject:[self getGeolocationsMessageWithBubbleMessageType:(i % 7) ? XHBubbleMessageTypeSending : XHBubbleMessageTypeReceiving]];
111111
}
112112

113113
for (NSUInteger i = 0; i < 3; i++) {
@@ -362,9 +362,9 @@ - (BOOL)shouldDisplayTimestampForRowAtIndexPath:(NSIndexPath *)indexPath {
362362
*/
363363
- (void)configureCell:(XHMessageTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
364364
if (indexPath.row % 4) {
365-
cell.messageBubbleView.messageDisplayTextView.textColor = [UIColor colorWithRed:0.106 green:0.586 blue:1.000 alpha:1.000];
365+
cell.messageBubbleView.displayTextView.textColor = [UIColor colorWithRed:0.106 green:0.586 blue:1.000 alpha:1.000];
366366
} else {
367-
cell.messageBubbleView.messageDisplayTextView.textColor = [UIColor blackColor];
367+
cell.messageBubbleView.displayTextView.textColor = [UIColor blackColor];
368368
}
369369
}
370370

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// NSMutableAttributedString+Helper.h
3+
// SECoreTextView
4+
//
5+
// Created by kishikawa katsumi on 2013/04/28.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <CoreText/CoreText.h>
11+
#import "SECompatibility.h"
12+
13+
@interface NSMutableAttributedString(Helper)
14+
15+
- (void)addFontAttribute:(NSFont *)font range:(NSRange)range;
16+
17+
@end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// NSMutableAttributedString+Helper.m
3+
// SECoreTextView
4+
//
5+
// Created by kishikawa katsumi on 2013/04/28.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "NSMutableAttributedString+Helper.h"
10+
11+
@implementation NSMutableAttributedString(Helper)
12+
13+
- (void)addFontAttribute:(NSFont *)font range:(NSRange)range
14+
{
15+
CFStringRef fontName = (__bridge CFStringRef)font.fontName;
16+
CGFloat fontSize = font.pointSize;
17+
CTFontRef ctfont = CTFontCreateWithName(fontName, fontSize, NULL);
18+
[self addAttributes:@{(id)kCTFontAttributeName: (__bridge id)ctfont} range:range];
19+
CFRelease(ctfont);
20+
}
21+
22+
@end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// SECompatibility.h
3+
// SECoreTextView
4+
//
5+
// Created by kishikawa katsumi on 2013/04/21.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#if TARGET_OS_IPHONE
12+
#import <UIKit/UIKit.h>
13+
14+
@compatibility_alias NSView UIView;
15+
@compatibility_alias NSFont UIFont;
16+
@compatibility_alias NSColor UIColor;
17+
@compatibility_alias NSBezierPath UIBezierPath;
18+
@compatibility_alias NSImage UIImage;
19+
20+
typedef UIEdgeInsets NSEdgeInsets;
21+
22+
#define NSEdgeInsetsMake UIEdgeInsetsMake
23+
#define NSRectFill UIRectFill
24+
#define NSStringFromRect NSStringFromCGRect
25+
#define NSStringFromSize NSStringFromCGSize
26+
#define NSTextInputClient UITextInput
27+
28+
extern NSString * const NSLinkAttributeName;
29+
extern NSString * const NSStrikethroughStyleAttributeName;
30+
31+
#else
32+
#import <Cocoa/Cocoa.h>
33+
34+
@compatibility_alias UIView NSView;
35+
@compatibility_alias UIFont NSFont;
36+
@compatibility_alias UIColor NSColor;
37+
@compatibility_alias UIBezierPath NSBezierPath;
38+
@compatibility_alias UIImage NSImage;
39+
40+
typedef NSEdgeInsets UIEdgeInsets;
41+
42+
#define UIEdgeInsetsMake NSEdgeInsetsMake
43+
#define UIRectFill NSRectFill
44+
#define NSStringFromCGRect NSStringFromRect
45+
#define NSStringFromCGSize NSStringFromSize
46+
#define UITextInput NSTextInputClient
47+
48+
@interface NSColor (Compatibility)
49+
50+
- (CGColorRef)createCGColor CF_RETURNS_RETAINED;
51+
52+
@end
53+
54+
#endif
55+
56+
@interface SECompatibility : NSObject
57+
58+
@end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// SECompatibility.m
3+
// SECoreTextView
4+
//
5+
// Created by kishikawa katsumi on 2013/04/21.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "SECompatibility.h"
10+
11+
#if TARGET_OS_IPHONE
12+
NSString * const NSLinkAttributeName = @"NSLink";
13+
NSString * const NSStrikethroughStyleAttributeName = @"NSStrikethrough";
14+
#else
15+
@implementation NSColor (Compatibility)
16+
17+
- (CGColorRef)createCGColor
18+
{
19+
const NSInteger numberOfComponents = [self numberOfComponents];
20+
CGFloat components[numberOfComponents];
21+
CGColorSpaceRef colorSpace = [[self colorSpace] CGColorSpace];
22+
23+
[self getComponents:(CGFloat *)&components];
24+
25+
return CGColorCreate(colorSpace, components);
26+
}
27+
28+
@end
29+
#endif
30+
31+
@implementation SECompatibility
32+
33+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// SEConstants.h
3+
// SECoreTextView-iOS
4+
//
5+
// Created by kishikawa katsumi on 2013/04/27.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "SECompatibility.h"
11+
12+
@interface SEConstants : NSObject
13+
14+
+ (NSColor *)selectedTextBackgroundColor;
15+
+ (NSColor *)linkColor;
16+
+ (NSColor *)selectionCaretColor;
17+
+ (NSColor *)caretColor;
18+
19+
@end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// SEConstants.m
3+
// SECoreTextView-iOS
4+
//
5+
// Created by kishikawa katsumi on 2013/04/27.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import "SEConstants.h"
10+
11+
@implementation SEConstants
12+
13+
+ (NSColor *)selectedTextBackgroundColor
14+
{
15+
#if TARGET_OS_IPHONE
16+
return [UIColor colorWithRed:0.654656 green:0.792518 blue:0.999198 alpha:1.0];
17+
#else
18+
return [NSColor selectedTextBackgroundColor];
19+
#endif
20+
}
21+
22+
+ (NSColor *)linkColor
23+
{
24+
#if TARGET_OS_IPHONE
25+
return [UIColor colorWithRed:0.286 green:0.549 blue:0.859 alpha:1.000];
26+
#else
27+
return [NSColor colorWithCalibratedRed:0.286 green:0.549 blue:0.859 alpha:1.000];
28+
#endif
29+
}
30+
31+
+ (NSColor *)selectionCaretColor
32+
{
33+
#if TARGET_OS_IPHONE
34+
return [UIColor colorWithRed:0.075 green:0.435 blue:0.882 alpha:1.000];
35+
#else
36+
return [NSColor colorWithCalibratedRed:0.075 green:0.435 blue:0.882 alpha:1.000];
37+
#endif
38+
}
39+
40+
+ (UIColor *)caretColor
41+
{
42+
#if TARGET_OS_IPHONE
43+
return [UIColor colorWithRed:0.118 green:0.447 blue:0.871 alpha:1.000];
44+
#else
45+
return [NSColor colorWithCalibratedRed:0.118 green:0.447 blue:0.871 alpha:1.000];
46+
#endif
47+
}
48+
49+
@end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// SELine.h
3+
// SECoreTextView
4+
//
5+
// Created by kishikawa katsumi on 2013/04/20.
6+
// Copyright (c) 2013 kishikawa katsumi. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <CoreText/CoreText.h>
11+
12+
@class SELinkText;
13+
14+
typedef struct {
15+
CGFloat ascent;
16+
CGFloat descent;
17+
CGFloat width;
18+
CGFloat leading;
19+
double trailingWhitespaceWidth;
20+
} SELineMetrics;
21+
22+
@interface SELineLayout : NSObject
23+
24+
@property (nonatomic, readonly) CTLineRef line;
25+
@property (nonatomic, readonly) NSInteger index;
26+
@property (nonatomic, readonly) CGRect rect;
27+
@property (nonatomic) CGRect drawingRect;
28+
@property (nonatomic) CGFloat truncationTokenWidth;
29+
@property (nonatomic, readonly) SELineMetrics metrics;
30+
31+
@property (nonatomic, readonly) NSRange stringRange;
32+
33+
@property (nonatomic, readonly) NSArray *links;
34+
@property (nonatomic, readonly) BOOL containsLink;
35+
@property (nonatomic, readonly) NSUInteger numberOfLinks;
36+
37+
@property (nonatomic, getter = isTruncated) BOOL truncated;
38+
39+
- (id)initWithLine:(CTLineRef)line index:(NSInteger)index rect:(CGRect)rect metrics:(SELineMetrics)metrics;
40+
41+
- (NSRange)stringRange;
42+
43+
- (BOOL)containsPoint:(CGPoint)point;
44+
- (CFIndex)stringIndexForPosition:(CGPoint)point;
45+
46+
- (CGRect)rectOfStringWithRange:(NSRange)range;
47+
48+
- (void)addLink:(SELinkText *)link;
49+
- (SELinkText *)linkAtPoint:(CGPoint)point;
50+
51+
@end

0 commit comments

Comments
 (0)