diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/.DS_Store" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/.DS_Store" index 6117f37..916bd45 100644 Binary files "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/.DS_Store" and "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/.DS_Store" differ diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.pbxproj" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.pbxproj" index 93fb64b..112f047 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.pbxproj" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.pbxproj" @@ -14,6 +14,7 @@ 860F857B1C36501F00D353C2 /* gifEmotion_4.gif in Resources */ = {isa = PBXBuildFile; fileRef = 860F85741C36501F00D353C2 /* gifEmotion_4.gif */; }; 860F857C1C36501F00D353C2 /* gifEmotion_5.gif in Resources */ = {isa = PBXBuildFile; fileRef = 860F85751C36501F00D353C2 /* gifEmotion_5.gif */; }; 860F857D1C36501F00D353C2 /* gifEmotion_6.gif in Resources */ = {isa = PBXBuildFile; fileRef = 860F85761C36501F00D353C2 /* gifEmotion_6.gif */; }; + 8627DCDE1E5419AF00481CCA /* CFTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8627DCDD1E5419AF00481CCA /* CFTableViewCell.m */; }; 864A419C1C3221A200839E11 /* CFTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 864A419B1C3221A200839E11 /* CFTextView.m */; }; 864A419F1C32220E00839E11 /* CFTextModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 864A419E1C32220E00839E11 /* CFTextModel.m */; }; 864A41A11C32227300839E11 /* EmotionGifList.plist in Resources */ = {isa = PBXBuildFile; fileRef = 864A41A01C32227300839E11 /* EmotionGifList.plist */; }; @@ -67,6 +68,8 @@ 860F85741C36501F00D353C2 /* gifEmotion_4.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = gifEmotion_4.gif; sourceTree = ""; }; 860F85751C36501F00D353C2 /* gifEmotion_5.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = gifEmotion_5.gif; sourceTree = ""; }; 860F85761C36501F00D353C2 /* gifEmotion_6.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = gifEmotion_6.gif; sourceTree = ""; }; + 8627DCDC1E5419AF00481CCA /* CFTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFTableViewCell.h; sourceTree = ""; }; + 8627DCDD1E5419AF00481CCA /* CFTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CFTableViewCell.m; sourceTree = ""; }; 864A419A1C3221A200839E11 /* CFTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFTextView.h; sourceTree = ""; }; 864A419B1C3221A200839E11 /* CFTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CFTextView.m; sourceTree = ""; }; 864A419D1C32220E00839E11 /* CFTextModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFTextModel.h; sourceTree = ""; }; @@ -194,6 +197,8 @@ 864A419E1C32220E00839E11 /* CFTextModel.m */, 864A419A1C3221A200839E11 /* CFTextView.h */, 864A419B1C3221A200839E11 /* CFTextView.m */, + 8627DCDC1E5419AF00481CCA /* CFTableViewCell.h */, + 8627DCDD1E5419AF00481CCA /* CFTableViewCell.m */, 86DC36531C30DCEB0045F2C6 /* Main.storyboard */, 86DC36561C30DCEB0045F2C6 /* Assets.xcassets */, 86DC36581C30DCEB0045F2C6 /* LaunchScreen.storyboard */, @@ -420,6 +425,7 @@ 86DC369B1C30DD0D0045F2C6 /* NSData+ImageContentType.m in Sources */, 864A419C1C3221A200839E11 /* CFTextView.m in Sources */, 86DC36A01C30DD0D0045F2C6 /* SDWebImageDownloaderOperation.m in Sources */, + 8627DCDE1E5419AF00481CCA /* CFTableViewCell.m in Sources */, 864A41BF1C32613300839E11 /* CFTextAttachment.m in Sources */, 86DC36A71C30DD0D0045F2C6 /* UIImageView+WebCache.m in Sources */, 86DC36A11C30DD0D0045F2C6 /* SDWebImageManager.m in Sources */, diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcshareddata/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcscmblueprint" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcshareddata/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcscmblueprint" new file mode 100644 index 0000000..857593b --- /dev/null +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcshareddata/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcscmblueprint" @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "B2CBDD9BE3727E57984017C50D692600B2AD0D06", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "B2CBDD9BE3727E57984017C50D692600B2AD0D06" : 9223372036854775807, + "DDE97A45152D06BAB7D0DE50BBF46B97CB854B85" : 9223372036854775807 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "FD3116A7-A2A4-47BA-9EC3-939DA44548A3", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "B2CBDD9BE3727E57984017C50D692600B2AD0D06" : "CFGifEmotionDemo\/", + "DDE97A45152D06BAB7D0DE50BBF46B97CB854B85" : "" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "11 - 动态表情", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "11 - 动态表情\/11 - 动态表情.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/yuchuanfeng\/CFGifEmotionDemo.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "B2CBDD9BE3727E57984017C50D692600B2AD0D06" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/yuchuanfeng\/CFHoveringTableViewDemo.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "DDE97A45152D06BAB7D0DE50BBF46B97CB854B85" + } + ] +} \ No newline at end of file diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcuserdata/yuchuanfeng.xcuserdatad/UserInterfaceState.xcuserstate" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcuserdata/yuchuanfeng.xcuserdatad/UserInterfaceState.xcuserstate" index 16e1e90..fdceaa0 100644 Binary files "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcuserdata/yuchuanfeng.xcuserdatad/UserInterfaceState.xcuserstate" and "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/project.xcworkspace/xcuserdata/yuchuanfeng.xcuserdatad/UserInterfaceState.xcuserstate" differ diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/xcuserdata/yuchuanfeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/xcuserdata/yuchuanfeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" index fe2b454..648f7a5 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/xcuserdata/yuchuanfeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205.xcodeproj/xcuserdata/yuchuanfeng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist" @@ -2,4 +2,40 @@ + + + + + + + + + + + + + + + + diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/Base.lproj/Main.storyboard" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/Base.lproj/Main.storyboard" index 8d5b337..49fa0f9 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/Base.lproj/Main.storyboard" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/Base.lproj/Main.storyboard" @@ -1,49 +1,115 @@ - - + + + + + - - + + - + - - - - - - + + - - - - - - - - - Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident + + + + + + + + + + + + + sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.h" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.h" new file mode 100644 index 0000000..dea8b3a --- /dev/null +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.h" @@ -0,0 +1,14 @@ +// +// CFTableViewCell.h +// 11 - 动态表情 +// +// Created by 于传峰 on 2017/2/15. +// Copyright © 2017年 于传峰. All rights reserved. +// + +#import + +@interface CFTableViewCell : UITableViewCell +@property (weak, nonatomic) IBOutlet UITextView *textView; + +@end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.m" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.m" new file mode 100644 index 0000000..6ae0baa --- /dev/null +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTableViewCell.m" @@ -0,0 +1,29 @@ +// +// CFTableViewCell.m +// 11 - 动态表情 +// +// Created by 于传峰 on 2017/2/15. +// Copyright © 2017年 于传峰. All rights reserved. +// + +#import "CFTableViewCell.h" + +@interface CFTableViewCell() + + +@end + +@implementation CFTableViewCell + +- (void)awakeFromNib { + [super awakeFromNib]; + // Initialization code +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + [super setSelected:selected animated:animated]; + + // Configure the view for the selected state +} + +@end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextAttachment.h" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextAttachment.h" index 11f769c..4267659 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextAttachment.h" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextAttachment.h" @@ -8,6 +8,8 @@ #import +#define gifRect CGRectMake(0, 0, 60, 50) + @interface CFTextAttachment : NSTextAttachment @property (nonatomic, copy) NSString *gifName; @end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.h" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.h" index 632bb20..550dc4f 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.h" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.h" @@ -7,9 +7,11 @@ // #import +#import @interface CFTextModel : NSObject @property (nonatomic, strong) NSMutableAttributedString *attributedString; @property (nonatomic, copy) NSString *contentString; +@property (nonatomic, assign) CGFloat height; @end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.m" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.m" index 93ea11b..daa6cef 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.m" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextModel.m" @@ -10,6 +10,8 @@ #import #import "CFTextAttachment.h" + + @implementation CFTextModel - (void)setContentString:(NSString *)contentString @@ -31,7 +33,7 @@ - (void)setContentString:(NSString *)contentString if (gifName) { gifEomtionDict[NSStringFromRange(NSMakeRange(result.range.location, resultString.length))] = gifName; - NSLog(@"%@----%@====%@", resultString, gifName, gifEomtionDict); +// NSLog(@"%@----%@====%@", resultString, gifName, gifEomtionDict); } }]; @@ -50,7 +52,7 @@ - (void)setContentString:(NSString *)contentString for (NSString* rangeString in ranges) { CFTextAttachment* attachment = [[CFTextAttachment alloc] init]; - attachment.bounds = CGRectMake(0, 0, 60, 50); + attachment.bounds = gifRect; attachment.gifName = gifEomtionDict[rangeString]; NSAttributedString* attachmentString = [NSAttributedString attributedStringWithAttachment:attachment]; [attributedString replaceCharactersInRange:NSRangeFromString(rangeString) withAttributedString:attachmentString]; @@ -58,7 +60,21 @@ - (void)setContentString:(NSString *)contentString [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, attributedString.length)]; [attributedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17] range:NSMakeRange(0, attributedString.length)]; + + NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc] init]; + [paragraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]]; + paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; + paragraphStyle.lineSpacing = 10; + [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)]; + self.attributedString = attributedString; } +- (void)setAttributedString:(NSMutableAttributedString *)attributedString +{ + _attributedString = attributedString; + self.height = [attributedString boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-40 , CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesDeviceMetrics|NSStringDrawingTruncatesLastVisibleLine context:NULL].size.height+20; + NSLog(@"heigt = %f", self.height); +} + @end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextView.m" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextView.m" index ac49a3d..3782c3b 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextView.m" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/CFTextView.m" @@ -12,6 +12,15 @@ @implementation CFTextView +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) + { + + } + return self; +} + - (void)setAttributedText:(NSAttributedString *)attributedText { [super setAttributedText:attributedText]; @@ -22,19 +31,22 @@ - (void)setAttributedText:(NSAttributedString *)attributedText } [self.attributedText enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, self.attributedText.length) options:NSAttributedStringEnumerationReverse usingBlock:^(CFTextAttachment* value, NSRange range, BOOL * _Nonnull stop) { - if (value && CGRectEqualToRect(value.bounds, CGRectMake(0, 0, 60, 50))) { + if (value && CGRectEqualToRect(value.bounds, gifRect)) { self.selectedRange = range; CGRect rect = [self firstRectForRange:self.selectedTextRange]; - self.selectedRange = NSMakeRange(0, 0); + rect.origin.y += (rect.size.height - gifRect.size.height); + rect.size = gifRect.size; UIImageView* imageView = [[UIImageView alloc] init]; [self addSubview:imageView]; imageView.frame = rect; imageView.image = [UIImage sd_animatedGIFNamed:value.gifName]; +// NSLog(@"\n rect = %@ \ncount = %@", NSStringFromCGRect(rect), [self selectionRectsForRange:self.selectedTextRange]); + // imageView.backgroundColor = [UIColor greenColor]; } }]; - + self.selectedRange = NSMakeRange(0, 0); } @end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.h" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.h" index b84fab6..351a578 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.h" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.h" @@ -8,7 +8,7 @@ #import -@interface ViewController : UIViewController +@interface ViewController : UITableViewController @end diff --git "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.m" "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.m" index c68fb7d..e8c8327 100644 --- "a/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.m" +++ "b/11 - \345\212\250\346\200\201\350\241\250\346\203\205/11 - \345\212\250\346\200\201\350\241\250\346\203\205/ViewController.m" @@ -10,21 +10,58 @@ #import "UIImage+GIF.h" #import "CFTextModel.h" #import "CFTextView.h" +#import "CFTableViewCell.h" @interface ViewController () -@property (weak, nonatomic) IBOutlet CFTextView *textView; - +@property (nonatomic, strong) NSMutableArray *models; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. - CFTextModel* model = [[CFTextModel alloc] init]; - model.contentString = @"/咸蛋超人“没人在乎你怎样在深夜痛哭,/飞翔/飞翔/飞翔也没人在乎你辗转反侧的要熬几个秋。外人只看结果,/奥特曼自己独撑过程。/点头等你明白了这个道理,便不会再在人前矫情,/我撞四处诉说以求宽慰。/烧烤”当你知道了许多真实、虚假的东西,/咸蛋超人也就没有那么多酸情了。你越来越沉默,越来越不想说。/心烦"; - self.textView.attributedText = model.attributedString; + +// self.tableView.rowHeight = UITableViewAutomaticDimension; + + self.models = [[NSMutableArray alloc] init]; + for ( int i = 0; i<100; i++ ) + { + CFTextModel* model = [[CFTextModel alloc] init]; + if (i % 2) + { + model.contentString = @"/咸蛋超人“没人在乎你怎样在深夜痛哭,/飞翔/飞翔/飞翔也没人在乎你辗转反侧的要熬几个/我撞秋。/我撞"; + }else{ + model.contentString = @"/点头等你明白了这个道理,便不会再在人前矫情,/我撞四处诉说以求宽慰。/烧烤”当你知道了许多真实、虚假的东西,/我撞也就没有那么多酸情了。你越来越沉默,越来越不想说。/心烦"; + [model.attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, model.attributedString.length)]; + } + [self.models addObject:model]; + } +// self.textView.attributedText = model.attributedString; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return 100; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + CFTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; + CFTextModel* model = self.models[indexPath.row]; + cell.textView.attributedText = model.attributedString; + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + CFTextModel* model = self.models[indexPath.row]; + return model.height; } +//- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath +//{ +// return 40; +//} + @end