├── DDRichTextGif.gif
├── personal_showBac@2x.png
├── DDRichTextLib
├── reply_button@2x.png
├── SDWebImage
│ ├── nilPic.png
│ ├── UIImage+MultiFormat.h
│ ├── SDWebImageOperation.h
│ ├── UIImage+GIF.h
│ ├── SDWebImageDecoder.h
│ ├── UIImage+WebP.h
│ ├── NSData+ImageContentType.h
│ ├── UIView+WebCacheOperation.h
│ ├── NSData+ImageContentType.m
│ ├── SDWebImageCompat.m
│ ├── SDWebImageCompat.h
│ ├── UIView+WebCacheOperation.m
│ ├── UIImage+WebP.m
│ ├── SDWebImageDownloaderOperation.h
│ ├── SDWebImageDecoder.m
│ ├── UIImage+MultiFormat.m
│ ├── SDWebImagePrefetcher.h
│ ├── UIImageView+HighlightedWebCache.m
│ ├── MKAnnotationView+WebCache.m
│ ├── UIImageView+HighlightedWebCache.h
│ ├── UIImage+GIF.m
│ ├── SDWebImagePrefetcher.m
│ ├── MKAnnotationView+WebCache.h
│ ├── SDWebImageDownloader.h
│ ├── SDImageCache.h
│ ├── UIImageView+WebCache.m
│ ├── UIImageView+WebCache.h
│ ├── SDWebImageDownloader.m
│ ├── SDWebImageManager.h
│ └── UIButton+WebCache.m
├── button_send_comment@2x.png
├── YMTapGestureRecongnizer.m
├── YMButton.h
├── YMTapGestureRecongnizer.h
├── NSArray+NSArray_ILExtension.h
├── YMButton.m
├── NSString+NSString_ILExtension.h
├── ILRegularExpressionManager.h
├── YMShowImageView.h
├── ContantHead.h
├── NSArray+NSArray_ILExtension.m
├── WFTextView.h
├── DDRichTextViewController.h
├── YMReplyInputView.h
├── YMTableViewCell.h
├── YMTextData.h
├── NSString+NSString_ILExtension.m
├── ILRegularExpressionManager.m
├── YMShowImageView.m
├── YMTextData.m
├── DDRichTextViewController.m
└── YMTableViewCell.m
├── DDRichText.xcodeproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── DDRichText
├── TestViewController.h
├── AppDelegate.h
├── main.m
├── Images.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── AppDelegate.m
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.xib
└── TestViewController.m
├── DDRichText.podspec
├── .gitignore
├── DDRichTextTests
├── Info.plist
└── DDRichTextTests.m
├── README.md
└── LICENSE
/DDRichTextGif.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daiweilai/DDRichText/HEAD/DDRichTextGif.gif
--------------------------------------------------------------------------------
/personal_showBac@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daiweilai/DDRichText/HEAD/personal_showBac@2x.png
--------------------------------------------------------------------------------
/DDRichTextLib/reply_button@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daiweilai/DDRichText/HEAD/DDRichTextLib/reply_button@2x.png
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/nilPic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daiweilai/DDRichText/HEAD/DDRichTextLib/SDWebImage/nilPic.png
--------------------------------------------------------------------------------
/DDRichTextLib/button_send_comment@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daiweilai/DDRichText/HEAD/DDRichTextLib/button_send_comment@2x.png
--------------------------------------------------------------------------------
/DDRichText.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTapGestureRecongnizer.m:
--------------------------------------------------------------------------------
1 | //
2 | // YMTapGestureRecongnizer.m
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/3.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "YMTapGestureRecongnizer.h"
10 |
11 | @implementation YMTapGestureRecongnizer
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/DDRichText/TestViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // TestViewController.h
3 | // WFCoretext
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "DDRichTextViewController.h"
10 |
11 | @interface TestViewController : DDRichTextViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMButton.h:
--------------------------------------------------------------------------------
1 | //
2 | // YMButton.h
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/4.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface YMButton : UIButton
12 |
13 | @property (nonatomic,strong) NSIndexPath * appendIndexPath;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/DDRichText/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // DDRichText
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 DavidDay. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+MultiFormat.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.h
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (MultiFormat)
12 |
13 | + (UIImage *)sd_imageWithData:(NSData *)data;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTapGestureRecongnizer.h:
--------------------------------------------------------------------------------
1 | //
2 | // YMTapGestureRecongnizer.h
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/3.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface YMTapGestureRecongnizer : UITapGestureRecognizer
12 |
13 | @property (nonatomic,strong) NSArray *appendArray;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/DDRichTextLib/NSArray+NSArray_ILExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+NSArray_ILExtension.h
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSArray (NSArray_ILExtension)
12 |
13 | - (NSArray *)offsetRangesInArrayBy:(NSUInteger)offset;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/DDRichText/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // DDRichText
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 DavidDay. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 |
11 | @protocol SDWebImageOperation
12 |
13 | - (void)cancel;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMButton.m:
--------------------------------------------------------------------------------
1 | //
2 | // YMButton.m
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/4.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "YMButton.h"
10 |
11 | @implementation YMButton
12 |
13 | /*
14 | // Only override drawRect: if you perform custom drawing.
15 | // An empty implementation adversely affects performance during animation.
16 | - (void)drawRect:(CGRect)rect {
17 | // Drawing code
18 | }
19 | */
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+GIF.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.h
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (GIF)
12 |
13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name;
14 |
15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data;
16 |
17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/DDRichTextLib/NSString+NSString_ILExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+NSString_ILExtension.h
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSString (NSString_ILExtension)
12 |
13 | - (NSString *)replaceCharactersAtIndexes:(NSArray *)indexes withString:(NSString *)aString;
14 |
15 |
16 | - (NSMutableArray *)itemsForPattern:(NSString *)pattern captureGroupIndex:(NSUInteger)index;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageDecoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import
12 | #import "SDWebImageCompat.h"
13 |
14 | @interface UIImage (ForceDecode)
15 |
16 | + (UIImage *)decodedImageWithImage:(UIImage *)image;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/DDRichText.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "DDRichText"
3 | s.version = "1.0.0"
4 | s.summary = "Just like Weixin Moment and Weibo RichText"
5 | s.homepage = "https://github.com/daiweilai/DDRichText"
6 | s.license = "Apache License"
7 | s.author = { "David Day" => "daiweilai@gmail.com" }
8 | s.source = { :git => "https://github.com/daiweilai/DDRichText.git", :tag => 'v1.0.0'}
9 | s.source_files = 'DDRichTextLib','DDRichTextLib/**/*.{h,m}'
10 | s.requires_arc = true
11 | s.platform = :ios, '7.0'
12 | end
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 |
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | # Pods/
27 |
--------------------------------------------------------------------------------
/DDRichTextLib/ILRegularExpressionManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // ILRegularExpressionManager.h
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ILRegularExpressionManager : NSObject
12 |
13 | + (NSArray *)itemIndexesWithPattern:(NSString *)pattern inString:(NSString *)findingString;
14 |
15 | + (NSMutableArray *)matchMobileLink:(NSString *)pattern;
16 |
17 | + (NSMutableArray *)matchWebLink:(NSString *)pattern;
18 |
19 | + (NSMutableArray *)matchName:(NSString *)pattern;
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+WebP.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+WebP.h
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #ifdef SD_WEBP
10 |
11 | #import
12 |
13 | // Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
14 | void WebPInitPremultiplyNEON(void);
15 |
16 | void WebPInitUpsamplersNEON(void);
17 |
18 | void VP8DspInitNEON(void);
19 |
20 | @interface UIImage (WebP)
21 |
22 | + (UIImage *)sd_imageWithWebPData:(NSData *)data;
23 |
24 | @end
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMShowImageView.h:
--------------------------------------------------------------------------------
1 | //
2 | // YMShowImageView.h
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/3.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | typedef void(^didRemoveImage)(void);
12 |
13 | @interface YMShowImageView : UIView
14 | {
15 | UIImageView *showImage;
16 | }
17 | @property (nonatomic,copy) didRemoveImage removeImg;
18 |
19 | - (void)show:(UIView *)bgView didFinish:(didRemoveImage)tempBlock;
20 |
21 | - (id)initWithFrame:(CGRect)frame byClick:(NSInteger)clickTag appendArray:(NSArray *)appendArray;
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/NSData+ImageContentType.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import
7 |
8 | @interface NSData (ImageContentType)
9 |
10 | /**
11 | * Compute the content type for an image data
12 | *
13 | * @param data the input data
14 | *
15 | * @return the content type as string (i.e. image/jpeg, image/gif)
16 | */
17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data;
18 |
19 | @end
20 |
21 |
22 | @interface NSData (ImageContentTypeDeprecated)
23 |
24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/DDRichTextTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.DavidDay.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/DDRichTextLib/ContantHead.h:
--------------------------------------------------------------------------------
1 | //
2 | // ContantHead.h
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/29.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #ifndef WFCoretext_ContantHead_h
10 | #define WFCoretext_ContantHead_h
11 |
12 | #define dataCount 10
13 | #define kLocationToBottom 20
14 |
15 | #define TableHeader 50
16 | #define ShowImage_H 80
17 | #define PlaceHolder @" "
18 | #define offSet_X 20
19 | #define EmotionItemPattern @"\\[em:(\\d+):\\]"
20 | #define NamePattern @"@\\w*\\s|@\\w*:|@\\w*:" //只能匹配 @姓名 @姓名: @姓名: 姓名只能使用数字、字母、下划线、汉字
21 |
22 | #define kDistance 20 //说说和图片的间隔
23 | #define kReplyBtnDistance 30 //回复按钮距离
24 | #define AttributedImageNameKey @"ImageName"
25 |
26 | #define screenWidth [UIScreen mainScreen].bounds.size.width
27 | #define screenHeight [UIScreen mainScreen].bounds.size.height
28 |
29 | #define limitline 4
30 | #define kSelf_SelectedColor [UIColor colorWithWhite:0 alpha:0.4] //点击背景 颜色
31 | #define kUserName_SelectedColor [UIColor colorWithWhite:0 alpha:0.25]//点击姓名颜色
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/DDRichTextTests/DDRichTextTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // DDRichTextTests.m
3 | // DDRichTextTests
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 DavidDay. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface DDRichTextTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation DDRichTextTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/DDRichTextLib/NSArray+NSArray_ILExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+NSArray_ILExtension.m
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "NSArray+NSArray_ILExtension.h"
10 |
11 | @implementation NSArray (NSArray_ILExtension)
12 |
13 | - (NSArray *)offsetRangesInArrayBy:(NSUInteger)offset
14 | {
15 | NSUInteger aOffset = 0;
16 | NSUInteger prevLength = 0;
17 |
18 |
19 | NSMutableArray *ranges = [[NSMutableArray alloc] initWithCapacity:[self count]];
20 | for(NSInteger i = 0; i < [self count]; i++)
21 | {
22 | @autoreleasepool {
23 | NSRange range = [[self objectAtIndex:i] rangeValue];
24 | prevLength = range.length;
25 |
26 | range.location -= aOffset;
27 | range.length = offset;
28 | [ranges addObject:NSStringFromRange(range)];
29 |
30 | aOffset = aOffset + prevLength - offset;
31 | }
32 | }
33 |
34 | return ranges;
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIView+WebCacheOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @interface UIView (WebCacheOperation)
13 |
14 | /**
15 | * Set the image load operation (storage in a UIView based dictionary)
16 | *
17 | * @param operation the operation
18 | * @param key key for storing the operation
19 | */
20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
21 |
22 | /**
23 | * Cancel all operations for the current UIView and key
24 | *
25 | * @param key key for identifying the operations
26 | */
27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
28 |
29 | /**
30 | * Just remove the operations corresponding to the current UIView and key without cancelling them
31 | *
32 | * @param key key for identifying the operations
33 | */
34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/DDRichTextLib/WFTextView.h:
--------------------------------------------------------------------------------
1 | //
2 | // WFTextView.h
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/31.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 | /**
9 | * CTLine 去画
10 | *
11 | */
12 |
13 | #import
14 |
15 |
16 | @protocol WFCoretextDelegate
17 |
18 | - (void)clickWFCoretext:(NSString *)clickString;
19 | - (void)clickWFCoretext:(NSString *)clickString replyIndex:(NSInteger)index;
20 |
21 | @end
22 |
23 | @interface WFTextView : UIView
24 |
25 | typedef NS_ENUM(NSUInteger, TextType) { //弄一个枚举类型用来更改主题
26 | TextTypeContent = 0,
27 | TextTypeReply
28 | };
29 |
30 | @property (nonatomic,strong) NSAttributedString *attrEmotionString;
31 | @property (nonatomic,strong) NSArray *emotionNames;
32 | @property (nonatomic,assign) BOOL isDraw;
33 | @property (nonatomic,assign) BOOL isFold;//是否折叠
34 | @property (nonatomic,strong) NSMutableArray *attributedData;
35 | @property (nonatomic,assign) int textLine;
36 | @property (nonatomic,assign) iddelegate;
37 | @property (nonatomic,assign) CFIndex limitCharIndex;//限制行的最后一个char的index
38 | @property (nonatomic,assign) TextType type;
39 | @property (nonatomic,assign) NSInteger replyIndex;
40 |
41 |
42 | - (void)setOldString:(NSString *)oldString andNewString:(NSString *)newString;
43 |
44 | - (int)getTextLines;
45 |
46 | - (float)getTextHeight;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/DDRichTextLib/DDRichTextViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // DDRichTextViewController.h
3 | // Created by David on 15/2/6.
4 | // Copyright (c) 2015年 tigerwf. All rights reserved.
5 | //
6 |
7 | #import
8 | #import "YMTableViewCell.h"
9 | #import "ContantHead.h"
10 | #import "YMShowImageView.h"
11 | #import "YMTextData.h"
12 | #import "YMReplyInputView.h"
13 |
14 |
15 | @protocol DDRichTextViewDelegate
16 | @required
17 | -(NSString*)senderName;//评论的时候自己的名字
18 | @optional
19 | -(BOOL)hideReplyButtonForIndex:(NSInteger)index;//是否隐藏回复按钮
20 | -(void)didPromulgatorPressForIndex:(NSInteger)index name:(NSString*)name;//发布者的头像或者名字被点击
21 | -(void)didRichTextPressedFromText:(NSString*)text index:(NSInteger)index;//正文的富文本被点击的回调
22 | -(void)didRichTextPressedFromText:(NSString*)text index:(NSInteger)index replyIndex:(NSInteger)replyIndex;//评论的富文本被点击的回调
23 | -(void)replyForIndex:(NSInteger)index replyText:(NSString*)text;//回复文字的回调
24 | @end
25 |
26 |
27 | @protocol DDRichTextViewDataSource
28 | @required
29 | -(YMTextData*)dataForRowAtIndex:(NSInteger)index;
30 | -(NSInteger)numberOfRowsInDDRichText;
31 | @end
32 |
33 | @interface DDRichTextViewController : UIViewController
34 | @property (weak, nonatomic) id delegate;
35 | @property (weak, nonatomic) id dataSource;
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/DDRichText/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/NSData+ImageContentType.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import "NSData+ImageContentType.h"
7 |
8 |
9 | @implementation NSData (ImageContentType)
10 |
11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data {
12 | uint8_t c;
13 | [data getBytes:&c length:1];
14 | switch (c) {
15 | case 0xFF:
16 | return @"image/jpeg";
17 | case 0x89:
18 | return @"image/png";
19 | case 0x47:
20 | return @"image/gif";
21 | case 0x49:
22 | case 0x4D:
23 | return @"image/tiff";
24 | case 0x52:
25 | // R as RIFF for WEBP
26 | if ([data length] < 12) {
27 | return nil;
28 | }
29 |
30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
32 | return @"image/webp";
33 | }
34 |
35 | return nil;
36 | }
37 | return nil;
38 | }
39 |
40 | @end
41 |
42 |
43 | @implementation NSData (ImageContentTypeDeprecated)
44 |
45 | + (NSString *)contentTypeForImageData:(NSData *)data {
46 | return [self sd_contentTypeForImageData:data];
47 | }
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMReplyInputView.h:
--------------------------------------------------------------------------------
1 | //
2 | // HXReplyInputView.h
3 | // Hongxiu
4 | //
5 | // Created by 吴福虎 on 14-8-18.
6 | // Copyright (c) 2014年 FeeTan. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol InputDelegate
12 |
13 | - (void)YMReplyInputWithReply:(NSString *)replyText appendTag:(NSInteger)inputTag;
14 | - (void)destorySelf;
15 |
16 | @end
17 |
18 | @interface YMReplyInputView : UIView
19 | {
20 | CGFloat topGap;
21 | CGFloat keyboardAnimationDuration;
22 | UIViewAnimationCurve keyboardAnimationCurve;
23 | CGFloat keyboardHeight;
24 | int inputHeight;
25 | int inputHeightWithShadow;
26 | BOOL autoResizeOnKeyboardVisibilityChanged;
27 | UIView *tapView;
28 |
29 |
30 | }
31 |
32 |
33 | @property (strong, nonatomic) UIButton* sendButton;
34 | @property (strong, nonatomic) UITextView* textView;
35 | @property (strong, nonatomic) UILabel* lblPlaceholder;
36 | @property (strong, nonatomic) UIImageView* inputBackgroundView;
37 | @property (strong, nonatomic) UITextField *textViewBackgroundView;
38 | @property (assign, nonatomic) BOOL autoResizeOnKeyboardVisibilityChanged;
39 | @property (readwrite, nonatomic) CGFloat keyboardHeight;
40 | @property (assign, nonatomic) iddelegate;
41 | @property (assign, nonatomic) NSInteger replyTag;
42 |
43 |
44 |
45 | - (NSString*)text;
46 | - (void)setText:(NSString*)text;
47 | - (void)setPlaceholder:(NSString*)text;
48 | - (void)showCommentView;
49 | - (id) initWithFrame:(CGRect)frame andAboveView:(UIView *)bgView;
50 | - (void)disappear;
51 |
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTableViewCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // YMTableViewCell.h
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/28.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "YMTextData.h"
11 | #import "WFTextView.h"
12 | #import "YMButton.h"
13 |
14 |
15 | @protocol cellDelegate
16 |
17 | - (void)changeFoldState:(YMTextData *)ymD onCellRow:(NSInteger) cellStamp;
18 | - (void)showImageViewWithImageViews:(NSArray *)imageViews byClickWhich:(NSInteger)clickTag;
19 | -(void)didPromulgatorNameOrHeadPicPressedForIndex:(NSInteger)index name:(NSString*)name;
20 | -(void)didRichTextPress:(NSString*)text index:(NSInteger)index;
21 | -(void)didRichTextPress:(NSString*)text index:(NSInteger)index replyIndex:(NSInteger)index;
22 |
23 | @end
24 |
25 | @interface YMTableViewCell : UITableViewCell
26 |
27 | @property BOOL hideReply;
28 |
29 |
30 | //界面
31 | @property (nonatomic,strong) UIImageView * headerImage;
32 | @property(nonatomic , strong)UILabel *nameLbl;
33 | @property(nonatomic,strong)UILabel *introLbl;
34 | @property(nonatomic,strong)UIButton *foldBtn;
35 | @property(nonatomic,strong)UIImageView *replyImageView;
36 |
37 | //数据
38 | @property (nonatomic,strong) NSMutableArray * imageArray;
39 | @property (nonatomic,strong) NSMutableArray * ymTextArray;
40 | @property (nonatomic,strong) NSMutableArray * ymShuoshuoArray;
41 | @property (nonatomic,assign) id delegate;
42 | @property (nonatomic,assign) NSInteger stamp;
43 | @property (nonatomic,strong) YMButton *replyBtn;
44 |
45 | - (YMTextData*)getYMTextData;
46 |
47 | - (void)setYMViewWith:(YMTextData *)ymData;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageCompat.m:
--------------------------------------------------------------------------------
1 | //
2 | // SDWebImageCompat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 11/12/12.
6 | // Copyright (c) 2012 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "SDWebImageCompat.h"
10 |
11 | #if !__has_feature(objc_arc)
12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
13 | #endif
14 |
15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
16 | if (!image) {
17 | return nil;
18 | }
19 |
20 | if ([image.images count] > 0) {
21 | NSMutableArray *scaledImages = [NSMutableArray array];
22 |
23 | for (UIImage *tempImage in image.images) {
24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)];
25 | }
26 |
27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
28 | }
29 | else {
30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
31 | CGFloat scale = 1.0;
32 | if (key.length >= 8) {
33 | // Search @2x. at the end of the string, before a 3 to 4 extension length (only if key len is 8 or more @2x. + 4 len ext)
34 | NSRange range = [key rangeOfString:@"@2x." options:0 range:NSMakeRange(key.length - 8, 5)];
35 | if (range.location != NSNotFound) {
36 | scale = 2.0;
37 | }
38 | }
39 |
40 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
41 | image = scaledImage;
42 | }
43 | return image;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/DDRichText/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.DavidDay.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageCompat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | * (c) Jamie Pinkham
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | #import
11 |
12 | #ifdef __OBJC_GC__
13 | #error SDWebImage does not support Objective-C Garbage Collection
14 | #endif
15 |
16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
17 | #error SDWebImage doesn't support Deployement Target version < 5.0
18 | #endif
19 |
20 | #if !TARGET_OS_IPHONE
21 | #import
22 | #ifndef UIImage
23 | #define UIImage NSImage
24 | #endif
25 | #ifndef UIImageView
26 | #define UIImageView NSImageView
27 | #endif
28 | #else
29 |
30 | #import
31 |
32 | #endif
33 |
34 | #ifndef NS_ENUM
35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
36 | #endif
37 |
38 | #ifndef NS_OPTIONS
39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
40 | #endif
41 |
42 | #if OS_OBJECT_USE_OBJC
43 | #undef SDDispatchQueueRelease
44 | #undef SDDispatchQueueSetterSementics
45 | #define SDDispatchQueueRelease(q)
46 | #define SDDispatchQueueSetterSementics strong
47 | #else
48 | #undef SDDispatchQueueRelease
49 | #undef SDDispatchQueueSetterSementics
50 | #define SDDispatchQueueRelease(q) (dispatch_release(q))
51 | #define SDDispatchQueueSetterSementics assign
52 | #endif
53 |
54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
55 |
56 | typedef void(^SDWebImageNoParamsBlock)();
57 |
58 | #define dispatch_main_sync_safe(block)\
59 | if ([NSThread isMainThread]) {\
60 | block();\
61 | } else {\
62 | dispatch_sync(dispatch_get_main_queue(), block);\
63 | }
64 |
65 | #define dispatch_main_async_safe(block)\
66 | if ([NSThread isMainThread]) {\
67 | block();\
68 | } else {\
69 | dispatch_async(dispatch_get_main_queue(), block);\
70 | }
71 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTextData.h:
--------------------------------------------------------------------------------
1 | //
2 | // YMTextData.h
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/29.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface YMTextData : NSObject
13 | //以下的数据需要初始化
14 | @property (nonatomic,strong) NSMutableArray *showImageArray;//图片数组 可以为nil
15 | @property (nonatomic,assign) BOOL foldOrNot;//是否折叠
16 | @property (nonatomic,strong) NSString *showShuoShuo;//说说部分 不能为nil
17 | @property (nonatomic,strong) NSMutableArray *defineAttrData;//自行添加 元素为每条回复中的自行添加的range组成的数组 如:第一条回复有(0,2)和(5,2) 第二条为(0,2)。。。。可以为nil
18 | @property (nonatomic,strong) NSMutableArray *replyDataSource;//回复内容数据源(未处理)可以为nil
19 | @property (nonatomic,strong)NSString *name;//发布说说人的姓名 可以为nil
20 | @property (nonatomic,strong)NSString *headPicURL;//发布说说人的头像 可以为nil 支持网络异步加载
21 | @property (nonatomic,strong)NSString *intro;//可以用来显示简介或者时间 可以为nil
22 |
23 |
24 |
25 |
26 | //以下数值不需要初始化
27 | @property (nonatomic,assign) float replyHeight;//回复高度
28 | @property (nonatomic,assign) float shuoshuoHeight;//折叠说说高度
29 | @property (nonatomic,assign) float unFoldShuoHeight;//展开说说高度
30 | @property (nonatomic,strong) NSMutableArray *completionReplySource;//回复内容数据源(处理)
31 | @property (nonatomic,strong) NSMutableArray *attributedData;//YMTextView附带的点击区域数组
32 | @property (nonatomic,strong) NSMutableArray *attributedDataWF;//WFTextView附带的点击区域数组
33 | @property (nonatomic,assign) float showImageHeight;//展示图片的高度
34 | @property (nonatomic,strong) NSString *completionShuoshuo;//说说部分(处理后)
35 | @property (nonatomic,assign) BOOL islessLimit;//是否小于最低限制 宏定义最低限制是 limitline
36 | /**
37 | * 计算高度
38 | *
39 | * @param sizeWidth view 宽度
40 | *
41 | * @return 返回高度
42 | */
43 | - (float) calculateReplyHeightWithWidth:(float)sizeWidth;
44 |
45 | /**
46 | * 计算折叠还是展开的说说的高度
47 | *
48 | * @param sizeWidth 宽度
49 | * @param isUnfold 展开与否
50 | *
51 | * @return 高度
52 | */
53 | - (float) calculateShuoshuoHeightWithWidth:(float)sizeWidth withUnFoldState:(BOOL)isUnfold;
54 |
55 |
56 |
57 | @end
58 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIView+WebCacheOperation.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIView+WebCacheOperation.h"
10 | #import "objc/runtime.h"
11 |
12 | static char loadOperationKey;
13 |
14 | @implementation UIView (WebCacheOperation)
15 |
16 | - (NSMutableDictionary *)operationDictionary {
17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
18 | if (operations) {
19 | return operations;
20 | }
21 | operations = [NSMutableDictionary dictionary];
22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
23 | return operations;
24 | }
25 |
26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
27 | [self sd_cancelImageLoadOperationWithKey:key];
28 | NSMutableDictionary *operationDictionary = [self operationDictionary];
29 | [operationDictionary setObject:operation forKey:key];
30 | }
31 |
32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
33 | // Cancel in progress downloader from queue
34 | NSMutableDictionary *operationDictionary = [self operationDictionary];
35 | id operations = [operationDictionary objectForKey:key];
36 | if (operations) {
37 | if ([operations isKindOfClass:[NSArray class]]) {
38 | for (id operation in operations) {
39 | if (operation) {
40 | [operation cancel];
41 | }
42 | }
43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){
44 | [(id) operations cancel];
45 | }
46 | [operationDictionary removeObjectForKey:key];
47 | }
48 | }
49 |
50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
51 | NSMutableDictionary *operationDictionary = [self operationDictionary];
52 | [operationDictionary removeObjectForKey:key];
53 | }
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/DDRichText/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // DDRichText
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 DavidDay. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+WebP.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+WebP.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #ifdef SD_WEBP
10 | #import "UIImage+WebP.h"
11 | #import "webp/decode.h"
12 |
13 | // Callback for CGDataProviderRelease
14 | static void FreeImageData(void *info, const void *data, size_t size)
15 | {
16 | free((void *)data);
17 | }
18 |
19 | @implementation UIImage (WebP)
20 |
21 | + (UIImage *)sd_imageWithWebPData:(NSData *)data {
22 | WebPDecoderConfig config;
23 | if (!WebPInitDecoderConfig(&config)) {
24 | return nil;
25 | }
26 |
27 | config.output.colorspace = MODE_rgbA;
28 | config.options.use_threads = 1;
29 |
30 | // Decode the WebP image data into a RGBA value array.
31 | if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) {
32 | return nil;
33 | }
34 |
35 | int width = config.input.width;
36 | int height = config.input.height;
37 | if (config.options.use_scaling) {
38 | width = config.options.scaled_width;
39 | height = config.options.scaled_height;
40 | }
41 |
42 | // Construct a UIImage from the decoded RGBA value array.
43 | CGDataProviderRef provider =
44 | CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
45 | CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
46 | CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
47 | CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
48 | CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
49 |
50 | CGColorSpaceRelease(colorSpaceRef);
51 | CGDataProviderRelease(provider);
52 |
53 | UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];
54 | CGImageRelease(imageRef);
55 |
56 | return image;
57 | }
58 |
59 | @end
60 |
61 | #if !COCOAPODS
62 | // Functions to resolve some undefined symbols when using WebP and force_load flag
63 | void WebPInitPremultiplyNEON(void) {}
64 | void WebPInitUpsamplersNEON(void) {}
65 | void VP8DspInitNEON(void) {}
66 | #endif
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/DDRichTextLib/NSString+NSString_ILExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+NSString_ILExtension.m
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "NSString+NSString_ILExtension.h"
10 |
11 | @implementation NSString (NSString_ILExtension)
12 |
13 | - (NSString *)replaceCharactersAtIndexes:(NSArray *)indexes withString:(NSString *)aString
14 | {
15 | NSAssert(indexes != nil, @"%s: indexes 不可以为nil", __PRETTY_FUNCTION__);
16 | NSAssert(aString != nil, @"%s: aString 不可以为nil", __PRETTY_FUNCTION__);
17 |
18 | NSUInteger offset = 0;
19 | NSMutableString *raw = [self mutableCopy];
20 |
21 | NSInteger prevLength = 0;
22 | for(NSInteger i = 0; i < [indexes count]; i++)
23 | {
24 | @autoreleasepool {
25 | NSRange range = [[indexes objectAtIndex:i] rangeValue];
26 | prevLength = range.length;
27 |
28 | range.location -= offset;
29 | [raw replaceCharactersInRange:range withString:aString];
30 | offset = offset + prevLength - [aString length];
31 | }
32 | }
33 |
34 | return raw;
35 | }
36 |
37 | - (NSMutableArray *)itemsForPattern:(NSString *)pattern captureGroupIndex:(NSUInteger)index
38 | {
39 | if ( !pattern )
40 | return nil;
41 |
42 | NSError *error = nil;
43 | NSRegularExpression *regx = [[NSRegularExpression alloc] initWithPattern:pattern
44 | options:NSRegularExpressionCaseInsensitive error:&error];
45 | if (error)
46 | {
47 |
48 | }
49 | else
50 | {
51 | NSMutableArray *results = [[NSMutableArray alloc] init];
52 | NSRange searchRange = NSMakeRange(0, [self length]);
53 | [regx enumerateMatchesInString:self options:0 range:searchRange usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
54 |
55 | NSRange groupRange = [result rangeAtIndex:index];
56 | NSString *match = [self substringWithRange:groupRange];
57 | [results addObject:match];
58 | }];
59 |
60 | return results;
61 | }
62 |
63 | return nil;
64 | }
65 |
66 |
67 | @end
68 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageDownloaderOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageDownloader.h"
11 | #import "SDWebImageOperation.h"
12 |
13 | @interface SDWebImageDownloaderOperation : NSOperation
14 |
15 | /**
16 | * The request used by the operation's connection.
17 | */
18 | @property (strong, nonatomic, readonly) NSURLRequest *request;
19 |
20 | /**
21 | * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default.
22 | *
23 | * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`.
24 | */
25 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage;
26 |
27 | /**
28 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
29 | *
30 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
31 | */
32 | @property (nonatomic, strong) NSURLCredential *credential;
33 |
34 | /**
35 | * The SDWebImageDownloaderOptions for the receiver.
36 | */
37 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
38 |
39 | /**
40 | * Initializes a `SDWebImageDownloaderOperation` object
41 | *
42 | * @see SDWebImageDownloaderOperation
43 | *
44 | * @param request the URL request
45 | * @param options downloader options
46 | * @param progressBlock the block executed when a new chunk of data arrives.
47 | * @note the progress block is executed on a background queue
48 | * @param completedBlock the block executed when the download is done.
49 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
50 | * @param cancelBlock the block executed if the download (operation) is cancelled
51 | *
52 | * @return the initialized instance
53 | */
54 | - (id)initWithRequest:(NSURLRequest *)request
55 | options:(SDWebImageDownloaderOptions)options
56 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
57 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock
58 | cancelled:(SDWebImageNoParamsBlock)cancelBlock;
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageDecoder.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import "SDWebImageDecoder.h"
12 |
13 | @implementation UIImage (ForceDecode)
14 |
15 | + (UIImage *)decodedImageWithImage:(UIImage *)image {
16 | if (image.images) {
17 | // Do not decode animated images
18 | return image;
19 | }
20 |
21 | CGImageRef imageRef = image.CGImage;
22 | CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
23 | CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize};
24 |
25 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
26 | CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
27 |
28 | int infoMask = (bitmapInfo & kCGBitmapAlphaInfoMask);
29 | BOOL anyNonAlpha = (infoMask == kCGImageAlphaNone ||
30 | infoMask == kCGImageAlphaNoneSkipFirst ||
31 | infoMask == kCGImageAlphaNoneSkipLast);
32 |
33 | // CGBitmapContextCreate doesn't support kCGImageAlphaNone with RGB.
34 | // https://developer.apple.com/library/mac/#qa/qa1037/_index.html
35 | if (infoMask == kCGImageAlphaNone && CGColorSpaceGetNumberOfComponents(colorSpace) > 1) {
36 | // Unset the old alpha info.
37 | bitmapInfo &= ~kCGBitmapAlphaInfoMask;
38 |
39 | // Set noneSkipFirst.
40 | bitmapInfo |= kCGImageAlphaNoneSkipFirst;
41 | }
42 | // Some PNGs tell us they have alpha but only 3 components. Odd.
43 | else if (!anyNonAlpha && CGColorSpaceGetNumberOfComponents(colorSpace) == 3) {
44 | // Unset the old alpha info.
45 | bitmapInfo &= ~kCGBitmapAlphaInfoMask;
46 | bitmapInfo |= kCGImageAlphaPremultipliedFirst;
47 | }
48 |
49 | // It calculates the bytes-per-row based on the bitsPerComponent and width arguments.
50 | CGContextRef context = CGBitmapContextCreate(NULL,
51 | imageSize.width,
52 | imageSize.height,
53 | CGImageGetBitsPerComponent(imageRef),
54 | 0,
55 | colorSpace,
56 | bitmapInfo);
57 | CGColorSpaceRelease(colorSpace);
58 |
59 | // If failed, return undecompressed image
60 | if (!context) return image;
61 |
62 | CGContextDrawImage(context, imageRect, imageRef);
63 | CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context);
64 |
65 | CGContextRelease(context);
66 |
67 | UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation];
68 | CGImageRelease(decompressedImageRef);
69 | return decompressedImage;
70 | }
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/DDRichText/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DDRichText
2 | This Framework is forked from https://github.com/TigerWf/WFCoretext . Just like Weixin Moment and Weibo RichText. On the base of original lib, Add many new features and make it easier to use
3 |
4 | Demo Snapshot
5 | -----------------------------------
6 | 
7 |
8 | Setup
9 | -----------------------------------
10 | #### CocoaPods
11 | With CocoaPods you can simply add `DDRichText` in your Podfile:
12 | ```
13 | pod 'DDRichText', '~> 1.0.0'
14 | ```
15 | #### Source File
16 | * Copy DDRichTextLib to your project
17 | * When you want to use DDRichText just like that
18 |
19 | #import "DDRichTextViewController.h"
20 |
21 | * Enjoy it
22 |
23 | Using
24 | -----------------------------------
25 | * Firstly, you should create a viewController and let it inherit DDRichTextViewController and implement DDRichTextViewDataSource,DDRichTextViewDelegate
26 | * Secondly, in your viewController add
27 |
28 | self.delegate = self;
29 | self.dataSource = self;
30 |
31 | *Thirdly you need to create an data model inherit YMTextData
32 |
33 | YMTextData *ymData = [[YMTextData alloc] init];
34 | ymData.showImageArray = _imageDataSource;
35 | ymData.foldOrNot = YES;
36 | ymData.showShuoShuo = @"this is contents";
37 | ymData.replyDataSource = _replyDataSource;
38 | ymData.name = @"David";
39 | ymData.intro = @"2015-2-8";
40 | ymData.headPic = [UIImage imageNamed:@"1.png"];
41 |
42 |
43 | * At last finish the dataSource and delegate methods just like the using of UITableView
44 |
45 | //@required
46 | -(YMTextData *)dataForRowAtIndex:(NSInteger)index{
47 | return [ymDataArray objectAtIndex:0];
48 | }
49 |
50 | -(NSInteger)numberOfRowsInDDRichText{
51 | return 5;
52 | }
53 |
54 | -(NSString *)senderName{
55 | return @"David";
56 | }
57 |
58 | //@optional
59 | -(BOOL)hideReplyButtonForIndex:(NSInteger)index;//hide replyButton
60 | -(void)didPromulgatorPressForIndex:(NSInteger)index name:(NSString*)name;//the publisher head was being pressed
61 | -(void)didRichTextPressedFromText:(NSString*)text index:(NSInteger)index;//the contents was being pressed
62 | -(void)didRichTextPressedFromText:(NSString*)text index:(NSInteger)index replyIndex:(NSInteger)replyIndex;//the reply was being pressed
63 | -(void)replyForIndex:(NSInteger)index replyText:(NSString*)text;//reply text callback
64 |
65 |
66 |
67 | Created By
68 | ------------
69 | * David Day(daiweilai)
70 |
71 | License
72 | -----------------------------------
73 | Copyright David Day(daiweilai)
74 |
75 | Licensed under the Apache License, Version 2.0 (the "License");
76 | you may not use this file except in compliance with the License.
77 | You may obtain a copy of the License at
78 |
79 | http://www.apache.org/licenses/LICENSE-2.0
80 |
81 | Unless required by applicable law or agreed to in writing, software
82 | distributed under the License is distributed on an "AS IS" BASIS,
83 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
84 | See the License for the specific language governing permissions and
85 | limitations under the License.
86 |
--------------------------------------------------------------------------------
/DDRichText/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+MultiFormat.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "UIImage+MultiFormat.h"
10 | #import "UIImage+GIF.h"
11 | #import "NSData+ImageContentType.h"
12 | #import
13 |
14 | #ifdef SD_WEBP
15 | #import "UIImage+WebP.h"
16 | #endif
17 |
18 | @implementation UIImage (MultiFormat)
19 |
20 | + (UIImage *)sd_imageWithData:(NSData *)data {
21 | UIImage *image;
22 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
23 | if ([imageContentType isEqualToString:@"image/gif"]) {
24 | image = [UIImage sd_animatedGIFWithData:data];
25 | }
26 | #ifdef SD_WEBP
27 | else if ([imageContentType isEqualToString:@"image/webp"])
28 | {
29 | image = [UIImage sd_imageWithWebPData:data];
30 | }
31 | #endif
32 | else {
33 | image = [[UIImage alloc] initWithData:data];
34 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
35 | if (orientation != UIImageOrientationUp) {
36 | image = [UIImage imageWithCGImage:image.CGImage
37 | scale:image.scale
38 | orientation:orientation];
39 | }
40 | }
41 |
42 |
43 | return image;
44 | }
45 |
46 |
47 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
48 | UIImageOrientation result = UIImageOrientationUp;
49 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
50 | if (imageSource) {
51 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
52 | if (properties) {
53 | CFTypeRef val;
54 | int exifOrientation;
55 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
56 | if (val) {
57 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
58 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
59 | } // else - if it's not set it remains at up
60 | CFRelease((CFTypeRef) properties);
61 | } else {
62 | //NSLog(@"NO PROPERTIES, FAIL");
63 | }
64 | CFRelease(imageSource);
65 | }
66 | return result;
67 | }
68 |
69 | #pragma mark EXIF orientation tag converter
70 | // Convert an EXIF image orientation to an iOS one.
71 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
72 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
73 | UIImageOrientation orientation = UIImageOrientationUp;
74 | switch (exifOrientation) {
75 | case 1:
76 | orientation = UIImageOrientationUp;
77 | break;
78 |
79 | case 3:
80 | orientation = UIImageOrientationDown;
81 | break;
82 |
83 | case 8:
84 | orientation = UIImageOrientationLeft;
85 | break;
86 |
87 | case 6:
88 | orientation = UIImageOrientationRight;
89 | break;
90 |
91 | case 2:
92 | orientation = UIImageOrientationUpMirrored;
93 | break;
94 |
95 | case 4:
96 | orientation = UIImageOrientationDownMirrored;
97 | break;
98 |
99 | case 5:
100 | orientation = UIImageOrientationLeftMirrored;
101 | break;
102 |
103 | case 7:
104 | orientation = UIImageOrientationRightMirrored;
105 | break;
106 | default:
107 | break;
108 | }
109 | return orientation;
110 | }
111 |
112 |
113 |
114 | @end
115 |
--------------------------------------------------------------------------------
/DDRichText/TestViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // TestViewController.m
3 | // WFCoretext
4 | //
5 | // Created by David on 15/2/7.
6 | // Copyright (c) 2015年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "TestViewController.h"
10 | #import "UIImageView+WebCache.h"
11 |
12 | @interface TestViewController ()
13 |
14 | @end
15 |
16 | @implementation TestViewController
17 | NSMutableArray * ymDataArray;
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 |
22 | self.title = @"DDRichText";
23 |
24 |
25 | //图片支持网络异步加载
26 | NSMutableArray *_imageDataSource = [NSMutableArray arrayWithCapacity:0];
27 | [_imageDataSource addObject:@"https://octodex.github.com/images/privateinvestocat.jpg"];
28 | [_imageDataSource addObject:@"https://octodex.github.com/images/gracehoppertocat.jpg"];
29 | [_imageDataSource addObject:@"https://octodex.github.com/images/jetpacktocat.png"];
30 | [_imageDataSource addObject:@"https://octodex.github.com/images/minertocat.png"];
31 | [_imageDataSource addObject:@"https://octodex.github.com/images/luchadortocat.png"];
32 | [_imageDataSource addObject:@"https://octodex.github.com/images/saritocat.png"];
33 | [_imageDataSource addObject:@"https://octodex.github.com/images/steroidtocat.png"];
34 |
35 | NSMutableArray *_replyDataSource = [[NSMutableArray alloc] init];//回复数据来源
36 | [_replyDataSource addObject:@"@Della:@戴伟来 DDRichText棒棒哒! @daiweilai: @daiweilai @戴伟来:I am Della,这是一个IOS库[em:01:][em:02:][em:03:]"];
37 |
38 | ymDataArray =[[NSMutableArray alloc]init];
39 |
40 | YMTextData *ymData = [[YMTextData alloc] init];
41 | ymData.showImageArray = _imageDataSource;
42 | ymData.foldOrNot = YES;
43 | ymData.showShuoShuo = @"这是DDRichText!!支持富文本并且文本能够收缩和伸展,支持图片,支持图片预览,能够回复,使用非常简单!!,这是一个电话号码13800138000,我是@戴伟来 @daiweilai: @daiweilai @戴伟来:支持自定义表情[em:01:] [em:02:] [em:03:] 这是一个网址https://github.com/daiweilai 也支持自定义位置的富文本点击!";
44 | ymData.replyDataSource = _replyDataSource;
45 | ymData.name = @"David";
46 | ymData.intro = @"2015-2-8";
47 | ymData.headPicURL = @"https://octodex.github.com/images/mummytocat.gif";
48 | [ymDataArray addObject:ymData];
49 | self.delegate = self;
50 | self.dataSource = self;
51 | }
52 |
53 | -(NSString *)senderName{
54 | return @"David";
55 | }
56 |
57 | - (void)didReceiveMemoryWarning {
58 | [super didReceiveMemoryWarning];
59 | }
60 |
61 | -(NSInteger)numberOfRowsInDDRichText{
62 | return 5;
63 | }
64 |
65 | -(YMTextData *)dataForRowAtIndex:(NSInteger)index{
66 | return [ymDataArray objectAtIndex:0];
67 | }
68 |
69 | -(BOOL)hideReplyButtonForIndex:(NSInteger)index{
70 | return NO;
71 | }
72 |
73 | -(void)didPromulgatorNameOrHeadPicPressedForIndex:(NSInteger)index name:(NSString *)name{
74 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"发布者回调" message:[NSString stringWithFormat:@"姓名:%@\n index:%d",name,index] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
75 | [alert show];
76 | }
77 |
78 |
79 | -(void)didRichTextPressedFromText:(NSString*)text index:(NSInteger)index{
80 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"正文富文本点击回调" message:[NSString stringWithFormat:@"点击的内容:%@\n index:%d",text,index] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
81 | [alert show];
82 | }
83 |
84 | -(void)didRichTextPressedFromText:(NSString *)text index:(NSInteger)index replyIndex:(NSInteger)replyIndex{
85 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"评论的富文本点击回调" message:[NSString stringWithFormat:@"点击的内容:%@\n index:%d \n replyIndex:%d",text,index,replyIndex] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
86 | [alert show];
87 | }
88 |
89 | -(void)replyForIndex:(NSInteger)index replyText:(NSString*)text{
90 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"回复的回调" message:[NSString stringWithFormat:@"回复的内容:%@\n index:%d",text,index] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
91 | [alert show];
92 | }
93 |
94 | @end
95 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImagePrefetcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @class SDWebImagePrefetcher;
13 |
14 | @protocol SDWebImagePrefetcherDelegate
15 |
16 | @optional
17 |
18 | /**
19 | * Called when an image was prefetched.
20 | *
21 | * @param imagePrefetcher The current image prefetcher
22 | * @param imageURL The image url that was prefetched
23 | * @param finishedCount The total number of images that were prefetched (successful or not)
24 | * @param totalCount The total number of images that were to be prefetched
25 | */
26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
27 |
28 | /**
29 | * Called when all images are prefetched.
30 | * @param imagePrefetcher The current image prefetcher
31 | * @param totalCount The total number of images that were prefetched (whether successful or not)
32 | * @param skippedCount The total number of images that were skipped
33 | */
34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
35 |
36 | @end
37 |
38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
40 |
41 | /**
42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
43 | */
44 | @interface SDWebImagePrefetcher : NSObject
45 |
46 | /**
47 | * The web image manager
48 | */
49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager;
50 |
51 | /**
52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3.
53 | */
54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
55 |
56 | /**
57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority.
58 | */
59 | @property (nonatomic, assign) SDWebImageOptions options;
60 |
61 | @property (weak, nonatomic) id delegate;
62 |
63 | /**
64 | * Return the global image prefetcher instance.
65 | */
66 | + (SDWebImagePrefetcher *)sharedImagePrefetcher;
67 |
68 | /**
69 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
70 | * currently one image is downloaded at a time,
71 | * and skips images for failed downloads and proceed to the next image in the list
72 | *
73 | * @param urls list of URLs to prefetch
74 | */
75 | - (void)prefetchURLs:(NSArray *)urls;
76 |
77 | /**
78 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
79 | * currently one image is downloaded at a time,
80 | * and skips images for failed downloads and proceed to the next image in the list
81 | *
82 | * @param urls list of URLs to prefetch
83 | * @param progressBlock block to be called when progress updates;
84 | * first parameter is the number of completed (successful or not) requests,
85 | * second parameter is the total number of images originally requested to be prefetched
86 | * @param completionBlock block to be called when prefetching is completed
87 | * first param is the number of completed (successful or not) requests,
88 | * second parameter is the number of skipped requests
89 | */
90 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
91 |
92 | /**
93 | * Remove and cancel queued list
94 | */
95 | - (void)cancelPrefetching;
96 |
97 |
98 | @end
99 |
--------------------------------------------------------------------------------
/DDRichTextLib/ILRegularExpressionManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // ILRegularExpressionManager.m
3 | // ILCoretext
4 | //
5 | // Created by 阿虎 on 14/10/22.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "ILRegularExpressionManager.h"
10 | #import "ContantHead.h"
11 |
12 | @implementation ILRegularExpressionManager
13 |
14 | + (NSArray *)itemIndexesWithPattern:(NSString *)pattern inString:(NSString *)findingString
15 | {
16 | NSAssert(pattern != nil, @"%s: pattern 不可以为 nil", __PRETTY_FUNCTION__);
17 | NSAssert(findingString != nil, @"%s: findingString 不可以为 nil", __PRETTY_FUNCTION__);
18 |
19 | NSError *error = nil;
20 | NSRegularExpression *regExp = [[NSRegularExpression alloc] initWithPattern:
21 | pattern options:NSRegularExpressionCaseInsensitive
22 | error:&error];
23 |
24 | // 查找匹配的字符串
25 | NSArray *result = [regExp matchesInString:findingString options:
26 | NSMatchingReportCompletion range:
27 | NSMakeRange(0, [findingString length])];
28 |
29 | if (error) {
30 | // NSLog(@"ERROR: %@", result);
31 | return nil;
32 | }
33 |
34 | NSUInteger count = [result count];
35 | // 没有查找到结果,返回空数组
36 | if (0 == count) {
37 | return [NSArray array];
38 | }
39 |
40 | // 将返回数组中的 NSTextCheckingResult 的实例的 range 取出生成新的 range 数组
41 | NSMutableArray *ranges = [[NSMutableArray alloc] init];
42 | for(NSInteger i = 0; i < count; i++)
43 | {
44 | @autoreleasepool {
45 | NSRange aRange = [[result objectAtIndex:i] range];
46 | [ranges addObject:[NSValue valueWithRange:aRange]];
47 | }
48 | }
49 |
50 | return ranges;
51 | }
52 |
53 | + (NSMutableArray *)matchMobileLink:(NSString *)pattern{
54 |
55 | NSMutableArray *linkArr = [NSMutableArray arrayWithCapacity:0];
56 | NSRegularExpression*regular=[[NSRegularExpression alloc]initWithPattern:@"(\\(86\\))?(13[0-9]|15[0-35-9]|18[0125-9])\\d{8}" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionCaseInsensitive error:nil];
57 |
58 | NSArray* array=[regular matchesInString:pattern options:0 range:NSMakeRange(0, [pattern length])];
59 |
60 | for( NSTextCheckingResult * result in array){
61 |
62 | NSString * string=[pattern substringWithRange:result.range];
63 | NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:string,NSStringFromRange(result.range), nil];
64 | [linkArr addObject:dic];
65 | }
66 |
67 | return linkArr;
68 | }
69 |
70 |
71 |
72 |
73 |
74 |
75 | + (NSMutableArray *)matchWebLink:(NSString *)pattern{
76 |
77 | // NSLog(@"go here? go here? go here ?");
78 |
79 | NSMutableArray *linkArr = [NSMutableArray arrayWithCapacity:0];
80 |
81 | NSRegularExpression*regular=[[NSRegularExpression alloc]initWithPattern:@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)" options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionCaseInsensitive error:nil];
82 |
83 | NSArray* array=[regular matchesInString:pattern options:0 range:NSMakeRange(0, [pattern length])];
84 |
85 | for( NSTextCheckingResult * result in array){
86 |
87 | NSString * string=[pattern substringWithRange:result.range];
88 |
89 | NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:string,NSStringFromRange(result.range), nil];
90 |
91 | [linkArr addObject:dic];
92 | }
93 | // NSLog(@"linkArr == %@",linkArr);
94 | return linkArr;
95 |
96 | }
97 |
98 | +(NSMutableArray*)matchName:(NSString*)pattern{
99 | NSMutableArray *linkArr = [NSMutableArray arrayWithCapacity:0];
100 |
101 | NSRegularExpression*regular=[[NSRegularExpression alloc]initWithPattern:NamePattern options:NSRegularExpressionDotMatchesLineSeparators|NSRegularExpressionCaseInsensitive error:nil];
102 |
103 | NSArray* array=[regular matchesInString:pattern options:0 range:NSMakeRange(0, [pattern length])];
104 |
105 | for( NSTextCheckingResult * result in array){
106 |
107 | NSString * string=[pattern substringWithRange:result.range];
108 |
109 | NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:string,NSStringFromRange(result.range), nil];
110 |
111 | [linkArr addObject:dic];
112 | }
113 | // NSLog(@"linkArr == %@",linkArr);
114 | return linkArr;
115 |
116 | }
117 |
118 | @end
119 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImageView+HighlightedWebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIImageView+HighlightedWebCache.h"
10 | #import "UIView+WebCacheOperation.h"
11 |
12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
13 |
14 | @implementation UIImageView (HighlightedWebCache)
15 |
16 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url {
17 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
18 | }
19 |
20 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
21 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
22 | }
23 |
24 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
25 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
26 | }
27 |
28 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
29 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
30 | }
31 |
32 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
33 | [self sd_cancelCurrentHighlightedImageLoad];
34 |
35 | if (url) {
36 | __weak UIImageView *wself = self;
37 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
38 | if (!wself) return;
39 | dispatch_main_sync_safe (^
40 | {
41 | if (!wself) return;
42 | if (image) {
43 | wself.highlightedImage = image;
44 | [wself setNeedsLayout];
45 | }
46 | if (completedBlock && finished) {
47 | completedBlock(image, error, cacheType, url);
48 | }
49 | });
50 | }];
51 | [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
52 | } else {
53 | dispatch_main_async_safe(^{
54 | NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
55 | if (completedBlock) {
56 | completedBlock(nil, error, SDImageCacheTypeNone, url);
57 | }
58 | });
59 | }
60 | }
61 |
62 | - (void)sd_cancelCurrentHighlightedImageLoad {
63 | [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
64 | }
65 |
66 | @end
67 |
68 |
69 | @implementation UIImageView (HighlightedWebCacheDeprecated)
70 |
71 | - (void)setHighlightedImageWithURL:(NSURL *)url {
72 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
73 | }
74 |
75 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
76 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
77 | }
78 |
79 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
80 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
81 | if (completedBlock) {
82 | completedBlock(image, error, cacheType);
83 | }
84 | }];
85 | }
86 |
87 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
88 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
89 | if (completedBlock) {
90 | completedBlock(image, error, cacheType);
91 | }
92 | }];
93 | }
94 |
95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
96 | [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
97 | if (completedBlock) {
98 | completedBlock(image, error, cacheType);
99 | }
100 | }];
101 | }
102 |
103 | - (void)cancelCurrentHighlightedImageLoad {
104 | [self sd_cancelCurrentHighlightedImageLoad];
105 | }
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/MKAnnotationView+WebCache.m:
--------------------------------------------------------------------------------
1 | //
2 | // MKAnnotationView+WebCache.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 14/03/12.
6 | // Copyright (c) 2012 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "MKAnnotationView+WebCache.h"
10 | #import "objc/runtime.h"
11 | #import "UIView+WebCacheOperation.h"
12 |
13 | static char imageURLKey;
14 |
15 | @implementation MKAnnotationView (WebCache)
16 |
17 | - (NSURL *)sd_imageURL {
18 | return objc_getAssociatedObject(self, &imageURLKey);
19 | }
20 |
21 | - (void)sd_setImageWithURL:(NSURL *)url {
22 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
23 | }
24 |
25 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
26 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
27 | }
28 |
29 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
30 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
31 | }
32 |
33 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
34 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
35 | }
36 |
37 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
38 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
39 | }
40 |
41 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
42 | [self sd_cancelCurrentImageLoad];
43 |
44 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
45 | self.image = placeholder;
46 |
47 | if (url) {
48 | __weak MKAnnotationView *wself = self;
49 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
50 | if (!wself) return;
51 | dispatch_main_sync_safe(^{
52 | __strong MKAnnotationView *sself = wself;
53 | if (!sself) return;
54 | if (image) {
55 | sself.image = image;
56 | }
57 | if (completedBlock && finished) {
58 | completedBlock(image, error, cacheType, url);
59 | }
60 | });
61 | }];
62 | [self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"];
63 | } else {
64 | dispatch_main_async_safe(^{
65 | NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
66 | if (completedBlock) {
67 | completedBlock(nil, error, SDImageCacheTypeNone, url);
68 | }
69 | });
70 | }
71 | }
72 |
73 | - (void)sd_cancelCurrentImageLoad {
74 | [self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"];
75 | }
76 |
77 | @end
78 |
79 |
80 | @implementation MKAnnotationView (WebCacheDeprecated)
81 |
82 | - (NSURL *)imageURL {
83 | return [self sd_imageURL];
84 | }
85 |
86 | - (void)setImageWithURL:(NSURL *)url {
87 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil];
88 | }
89 |
90 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
91 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
92 | }
93 |
94 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
95 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
96 | }
97 |
98 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
99 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
100 | if (completedBlock) {
101 | completedBlock(image, error, cacheType);
102 | }
103 | }];
104 | }
105 |
106 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
107 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
108 | if (completedBlock) {
109 | completedBlock(image, error, cacheType);
110 | }
111 | }];
112 | }
113 |
114 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
115 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
116 | if (completedBlock) {
117 | completedBlock(image, error, cacheType);
118 | }
119 | }];
120 | }
121 |
122 | - (void)cancelCurrentImageLoad {
123 | [self sd_cancelCurrentImageLoad];
124 | }
125 |
126 | @end
127 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImageView+HighlightedWebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 | #import "SDWebImageManager.h"
12 |
13 | /**
14 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
15 | */
16 | @interface UIImageView (HighlightedWebCache)
17 |
18 | /**
19 | * Set the imageView `highlightedImage` with an `url`.
20 | *
21 | * The download is asynchronous and cached.
22 | *
23 | * @param url The url for the image.
24 | */
25 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url;
26 |
27 | /**
28 | * Set the imageView `highlightedImage` with an `url` and custom options.
29 | *
30 | * The download is asynchronous and cached.
31 | *
32 | * @param url The url for the image.
33 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
34 | */
35 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
36 |
37 | /**
38 | * Set the imageView `highlightedImage` with an `url`.
39 | *
40 | * The download is asynchronous and cached.
41 | *
42 | * @param url The url for the image.
43 | * @param completedBlock A block called when operation has been completed. This block has no return value
44 | * and takes the requested UIImage as first parameter. In case of error the image parameter
45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
46 | * indicating if the image was retrived from the local cache or from the network.
47 | * The fourth parameter is the original image url.
48 | */
49 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
50 |
51 | /**
52 | * Set the imageView `highlightedImage` with an `url` and custom options.
53 | *
54 | * The download is asynchronous and cached.
55 | *
56 | * @param url The url for the image.
57 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
58 | * @param completedBlock A block called when operation has been completed. This block has no return value
59 | * and takes the requested UIImage as first parameter. In case of error the image parameter
60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
61 | * indicating if the image was retrived from the local cache or from the network.
62 | * The fourth parameter is the original image url.
63 | */
64 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
65 |
66 | /**
67 | * Set the imageView `highlightedImage` with an `url` and custom options.
68 | *
69 | * The download is asynchronous and cached.
70 | *
71 | * @param url The url for the image.
72 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
73 | * @param progressBlock A block called while image is downloading
74 | * @param completedBlock A block called when operation has been completed. This block has no return value
75 | * and takes the requested UIImage as first parameter. In case of error the image parameter
76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
77 | * indicating if the image was retrived from the local cache or from the network.
78 | * The fourth parameter is the original image url.
79 | */
80 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
81 |
82 | /**
83 | * Cancel the current download
84 | */
85 | - (void)sd_cancelCurrentHighlightedImageLoad;
86 |
87 | @end
88 |
89 |
90 | @interface UIImageView (HighlightedWebCacheDeprecated)
91 |
92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
97 |
98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImage+GIF.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.m
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "UIImage+GIF.h"
10 | #import
11 |
12 | @implementation UIImage (GIF)
13 |
14 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data {
15 | if (!data) {
16 | return nil;
17 | }
18 |
19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
20 |
21 | size_t count = CGImageSourceGetCount(source);
22 |
23 | UIImage *animatedImage;
24 |
25 | if (count <= 1) {
26 | animatedImage = [[UIImage alloc] initWithData:data];
27 | }
28 | else {
29 | NSMutableArray *images = [NSMutableArray array];
30 |
31 | NSTimeInterval duration = 0.0f;
32 |
33 | for (size_t i = 0; i < count; i++) {
34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
35 |
36 | duration += [self sd_frameDurationAtIndex:i source:source];
37 |
38 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
39 |
40 | CGImageRelease(image);
41 | }
42 |
43 | if (!duration) {
44 | duration = (1.0f / 10.0f) * count;
45 | }
46 |
47 | animatedImage = [UIImage animatedImageWithImages:images duration:duration];
48 | }
49 |
50 | CFRelease(source);
51 |
52 | return animatedImage;
53 | }
54 |
55 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
56 | float frameDuration = 0.1f;
57 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
58 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
59 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
60 |
61 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
62 | if (delayTimeUnclampedProp) {
63 | frameDuration = [delayTimeUnclampedProp floatValue];
64 | }
65 | else {
66 |
67 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
68 | if (delayTimeProp) {
69 | frameDuration = [delayTimeProp floatValue];
70 | }
71 | }
72 |
73 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
74 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
75 | // a duration of <= 10 ms. See and
76 | // for more information.
77 |
78 | if (frameDuration < 0.011f) {
79 | frameDuration = 0.100f;
80 | }
81 |
82 | CFRelease(cfFrameProperties);
83 | return frameDuration;
84 | }
85 |
86 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name {
87 | CGFloat scale = [UIScreen mainScreen].scale;
88 |
89 | if (scale > 1.0f) {
90 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
91 |
92 | NSData *data = [NSData dataWithContentsOfFile:retinaPath];
93 |
94 | if (data) {
95 | return [UIImage sd_animatedGIFWithData:data];
96 | }
97 |
98 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
99 |
100 | data = [NSData dataWithContentsOfFile:path];
101 |
102 | if (data) {
103 | return [UIImage sd_animatedGIFWithData:data];
104 | }
105 |
106 | return [UIImage imageNamed:name];
107 | }
108 | else {
109 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
110 |
111 | NSData *data = [NSData dataWithContentsOfFile:path];
112 |
113 | if (data) {
114 | return [UIImage sd_animatedGIFWithData:data];
115 | }
116 |
117 | return [UIImage imageNamed:name];
118 | }
119 | }
120 |
121 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
122 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
123 | return self;
124 | }
125 |
126 | CGSize scaledSize = size;
127 | CGPoint thumbnailPoint = CGPointZero;
128 |
129 | CGFloat widthFactor = size.width / self.size.width;
130 | CGFloat heightFactor = size.height / self.size.height;
131 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
132 | scaledSize.width = self.size.width * scaleFactor;
133 | scaledSize.height = self.size.height * scaleFactor;
134 |
135 | if (widthFactor > heightFactor) {
136 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
137 | }
138 | else if (widthFactor < heightFactor) {
139 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
140 | }
141 |
142 | NSMutableArray *scaledImages = [NSMutableArray array];
143 |
144 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
145 |
146 | for (UIImage *image in self.images) {
147 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
148 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
149 |
150 | [scaledImages addObject:newImage];
151 | }
152 |
153 | UIGraphicsEndImageContext();
154 |
155 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
156 | }
157 |
158 | @end
159 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImagePrefetcher.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImagePrefetcher.h"
10 |
11 | #if (!defined(DEBUG) && !defined (SD_VERBOSE)) || defined(SD_LOG_NONE)
12 | #define NSLog(...)
13 | #endif
14 |
15 | @interface SDWebImagePrefetcher ()
16 |
17 | @property (strong, nonatomic) SDWebImageManager *manager;
18 | @property (strong, nonatomic) NSArray *prefetchURLs;
19 | @property (assign, nonatomic) NSUInteger requestedCount;
20 | @property (assign, nonatomic) NSUInteger skippedCount;
21 | @property (assign, nonatomic) NSUInteger finishedCount;
22 | @property (assign, nonatomic) NSTimeInterval startedTime;
23 | @property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
24 | @property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
25 |
26 | @end
27 |
28 | @implementation SDWebImagePrefetcher
29 |
30 | + (SDWebImagePrefetcher *)sharedImagePrefetcher {
31 | static dispatch_once_t once;
32 | static id instance;
33 | dispatch_once(&once, ^{
34 | instance = [self new];
35 | });
36 | return instance;
37 | }
38 |
39 | - (id)init {
40 | if ((self = [super init])) {
41 | _manager = [SDWebImageManager new];
42 | _options = SDWebImageLowPriority;
43 | self.maxConcurrentDownloads = 3;
44 | }
45 | return self;
46 | }
47 |
48 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
49 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
50 | }
51 |
52 | - (NSUInteger)maxConcurrentDownloads {
53 | return self.manager.imageDownloader.maxConcurrentDownloads;
54 | }
55 |
56 | - (void)startPrefetchingAtIndex:(NSUInteger)index {
57 | if (index >= self.prefetchURLs.count) return;
58 | self.requestedCount++;
59 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
60 | if (!finished) return;
61 | self.finishedCount++;
62 |
63 | if (image) {
64 | if (self.progressBlock) {
65 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
66 | }
67 | NSLog(@"Prefetched %@ out of %@", @(self.finishedCount), @(self.prefetchURLs.count));
68 | }
69 | else {
70 | if (self.progressBlock) {
71 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
72 | }
73 | NSLog(@"Prefetched %@ out of %@ (Failed)", @(self.finishedCount), @(self.prefetchURLs.count));
74 |
75 | // Add last failed
76 | self.skippedCount++;
77 | }
78 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
79 | [self.delegate imagePrefetcher:self
80 | didPrefetchURL:self.prefetchURLs[index]
81 | finishedCount:self.finishedCount
82 | totalCount:self.prefetchURLs.count
83 | ];
84 | }
85 |
86 | if (self.prefetchURLs.count > self.requestedCount) {
87 | dispatch_async(dispatch_get_main_queue(), ^{
88 | [self startPrefetchingAtIndex:self.requestedCount];
89 | });
90 | }
91 | else if (self.finishedCount == self.requestedCount) {
92 | [self reportStatus];
93 | if (self.completionBlock) {
94 | self.completionBlock(self.finishedCount, self.skippedCount);
95 | self.completionBlock = nil;
96 | }
97 | }
98 | }];
99 | }
100 |
101 | - (void)reportStatus {
102 | NSUInteger total = [self.prefetchURLs count];
103 | NSLog(@"Finished prefetching (%@ successful, %@ skipped, timeElasped %.2f)", @(total - self.skippedCount), @(self.skippedCount), CFAbsoluteTimeGetCurrent() - self.startedTime);
104 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
105 | [self.delegate imagePrefetcher:self
106 | didFinishWithTotalCount:(total - self.skippedCount)
107 | skippedCount:self.skippedCount
108 | ];
109 | }
110 | }
111 |
112 | - (void)prefetchURLs:(NSArray *)urls {
113 | [self prefetchURLs:urls progress:nil completed:nil];
114 | }
115 |
116 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
117 | [self cancelPrefetching]; // Prevent duplicate prefetch request
118 | self.startedTime = CFAbsoluteTimeGetCurrent();
119 | self.prefetchURLs = urls;
120 | self.completionBlock = completionBlock;
121 | self.progressBlock = progressBlock;
122 |
123 | if(urls.count == 0){
124 | if(completionBlock){
125 | completionBlock(0,0);
126 | }
127 | }else{
128 | // Starts prefetching from the very first image on the list with the max allowed concurrency
129 | NSUInteger listCount = self.prefetchURLs.count;
130 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
131 | [self startPrefetchingAtIndex:i];
132 | }
133 | }
134 | }
135 |
136 | - (void)cancelPrefetching {
137 | self.prefetchURLs = nil;
138 | self.skippedCount = 0;
139 | self.requestedCount = 0;
140 | self.finishedCount = 0;
141 | [self.manager cancelAll];
142 | }
143 |
144 | @end
145 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMShowImageView.m:
--------------------------------------------------------------------------------
1 | //
2 | // YMShowImageView.m
3 | // WFCoretext
4 | //
5 | // Created by 吴福虎 on 14/11/3.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "YMShowImageView.h"
10 | #import "UIImageView+WebCache.h"
11 |
12 | @implementation YMShowImageView{
13 |
14 | UIScrollView *_scrollView;
15 | CGRect self_Frame;
16 | NSInteger page;
17 | BOOL doubleClick;
18 |
19 | }
20 |
21 |
22 |
23 | - (id)initWithFrame:(CGRect)frame byClick:(NSInteger)clickTag appendArray:(NSArray *)appendArray{
24 |
25 | self = [super initWithFrame:frame];
26 | if (self) {
27 |
28 | self_Frame = frame;
29 |
30 |
31 | self.alpha = 0.0f;
32 | page = 0;
33 | doubleClick = YES;
34 |
35 | [self configScrollViewWith:clickTag andAppendArray:appendArray];
36 |
37 | UITapGestureRecognizer *tapGser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disappear)];
38 | tapGser.numberOfTouchesRequired = 1;
39 | tapGser.numberOfTapsRequired = 1;
40 | [self addGestureRecognizer:tapGser];
41 |
42 | UITapGestureRecognizer *doubleTapGser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeBig:)];
43 | doubleTapGser.numberOfTapsRequired = 2;
44 | [self addGestureRecognizer:doubleTapGser];
45 | [tapGser requireGestureRecognizerToFail:doubleTapGser];
46 |
47 | }
48 | self.backgroundColor = [UIColor whiteColor];
49 | return self;
50 |
51 |
52 | }
53 |
54 | - (void)configScrollViewWith:(NSInteger)clickTag andAppendArray:(NSArray *)appendArray{
55 |
56 | _scrollView = [[UIScrollView alloc] initWithFrame:self_Frame];
57 | _scrollView.backgroundColor = [UIColor whiteColor];
58 | _scrollView.pagingEnabled = true;
59 | _scrollView.delegate = self;
60 | _scrollView.contentSize = CGSizeMake(self.frame.size.width * appendArray.count, 0);
61 | [self addSubview:_scrollView];
62 |
63 | float W = self.frame.size.width;
64 |
65 |
66 | for (int i = 0; i < appendArray.count; i ++) {
67 |
68 | UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(self.frame.size.width * i, 0, self.frame.size.width, self.frame.size.height)];
69 | imageScrollView.backgroundColor = [UIColor whiteColor];
70 | imageScrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height);
71 | imageScrollView.delegate = self;
72 | imageScrollView.maximumZoomScale = 4;
73 | imageScrollView.minimumZoomScale = 1;
74 |
75 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
76 | //这句话让图片支持网络异步加载
77 | [imageView sd_setImageWithURL:[NSURL URLWithString:[appendArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"nilPic.png"]];
78 | // UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[appendArray objectAtIndex:i]]];
79 | // imageView.image = img;
80 | imageView.contentMode = UIViewContentModeScaleAspectFit;
81 | [imageScrollView addSubview:imageView];
82 | [_scrollView addSubview:imageScrollView];
83 |
84 | imageScrollView.tag = 100 + i ;
85 | imageView.tag = 1000 + i;
86 |
87 |
88 | }
89 | [_scrollView setContentOffset:CGPointMake(W * (clickTag - 9999), 0) animated:YES];
90 | page = clickTag - 9999;
91 |
92 | }
93 |
94 | - (void)disappear{
95 |
96 | _removeImg();
97 |
98 | }
99 |
100 |
101 | - (void)changeBig:(UITapGestureRecognizer *)tapGes{
102 |
103 | CGFloat newscale = 1.9;
104 | UIScrollView *currentScrollView = (UIScrollView *)[self viewWithTag:page + 100];
105 | CGRect zoomRect = [self zoomRectForScale:newscale withCenter:[tapGes locationInView:tapGes.view] andScrollView:currentScrollView];
106 |
107 | if (doubleClick == YES) {
108 |
109 | [currentScrollView zoomToRect:zoomRect animated:YES];
110 |
111 | }else {
112 |
113 | [currentScrollView zoomToRect:currentScrollView.frame animated:YES];
114 | }
115 |
116 | doubleClick = !doubleClick;
117 |
118 | }
119 |
120 | - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
121 |
122 | UIImageView *imageView = (UIImageView *)[self viewWithTag:scrollView.tag + 900];
123 | return imageView;
124 |
125 | }
126 |
127 | - (CGRect)zoomRectForScale:(CGFloat)newscale withCenter:(CGPoint)center andScrollView:(UIScrollView *)scrollV{
128 |
129 | CGRect zoomRect = CGRectZero;
130 |
131 | zoomRect.size.height = scrollV.frame.size.height / newscale;
132 | zoomRect.size.width = scrollV.frame.size.width / newscale;
133 | zoomRect.origin.x = center.x - (zoomRect.size.width / 2.0);
134 | zoomRect.origin.y = center.y - (zoomRect.size.height / 2.0);
135 | // NSLog(@" === %f",zoomRect.origin.x);
136 | return zoomRect;
137 |
138 | }
139 |
140 | - (void)show:(UIView *)bgView didFinish:(didRemoveImage)tempBlock{
141 |
142 | [bgView addSubview:self];
143 |
144 | _removeImg = tempBlock;
145 |
146 | [UIView animateWithDuration:.4f animations:^(){
147 |
148 | self.alpha = 1.0f;
149 |
150 | } completion:^(BOOL finished) {
151 |
152 | }];
153 |
154 | }
155 |
156 |
157 | #pragma mark - ScorllViewDelegate
158 |
159 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
160 |
161 | CGPoint offset = _scrollView.contentOffset;
162 | page = offset.x / self.frame.size.width ;
163 |
164 |
165 | UIScrollView *scrollV_next = (UIScrollView *)[self viewWithTag:page+100+1]; //前一页
166 |
167 | if (scrollV_next.zoomScale != 1.0){
168 |
169 | scrollV_next.zoomScale = 1.0;
170 | }
171 |
172 | UIScrollView *scollV_pre = (UIScrollView *)[self viewWithTag:page+100-1]; //后一页
173 | if (scollV_pre.zoomScale != 1.0){
174 | scollV_pre.zoomScale = 1.0;
175 | }
176 |
177 | // NSLog(@"page == %d",page);
178 | }
179 |
180 | - (void)scrollViewDidZoom:(UIScrollView *)scrollView{
181 |
182 |
183 | }
184 |
185 | @end
186 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/MKAnnotationView+WebCache.h:
--------------------------------------------------------------------------------
1 | //
2 | // MKAnnotationView+WebCache.h
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 14/03/12.
6 | // Copyright (c) 2012 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "MapKit/MapKit.h"
10 | #import "SDWebImageManager.h"
11 |
12 | /**
13 | * Integrates SDWebImage async downloading and caching of remote images with MKAnnotationView.
14 | */
15 | @interface MKAnnotationView (WebCache)
16 |
17 | /**
18 | * Get the current image URL.
19 | *
20 | * Note that because of the limitations of categories this property can get out of sync
21 | * if you use sd_setImage: directly.
22 | */
23 | - (NSURL *)sd_imageURL;
24 |
25 | /**
26 | * Set the imageView `image` with an `url`.
27 | *
28 | * The download is asynchronous and cached.
29 | *
30 | * @param url The url for the image.
31 | */
32 | - (void)sd_setImageWithURL:(NSURL *)url;
33 |
34 | /**
35 | * Set the imageView `image` with an `url` and a placeholder.
36 | *
37 | * The download is asynchronous and cached.
38 | *
39 | * @param url The url for the image.
40 | * @param placeholder The image to be set initially, until the image request finishes.
41 | * @see sd_setImageWithURL:placeholderImage:options:
42 | */
43 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
44 |
45 | /**
46 | * Set the imageView `image` with an `url`, placeholder and custom options.
47 | *
48 | * The download is asynchronous and cached.
49 | *
50 | * @param url The url for the image.
51 | * @param placeholder The image to be set initially, until the image request finishes.
52 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
53 | */
54 |
55 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
56 |
57 | /**
58 | * Set the imageView `image` with an `url`.
59 | *
60 | * The download is asynchronous and cached.
61 | *
62 | * @param url The url for the image.
63 | * @param completedBlock A block called when operation has been completed. This block has no return value
64 | * and takes the requested UIImage as first parameter. In case of error the image parameter
65 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
66 | * indicating if the image was retrived from the local cache or from the network.
67 | * The fourth parameter is the original image url.
68 | */
69 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
70 |
71 | /**
72 | * Set the imageView `image` with an `url`, placeholder.
73 | *
74 | * The download is asynchronous and cached.
75 | *
76 | * @param url The url for the image.
77 | * @param placeholder The image to be set initially, until the image request finishes.
78 | * @param completedBlock A block called when operation has been completed. This block has no return value
79 | * and takes the requested UIImage as first parameter. In case of error the image parameter
80 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
81 | * indicating if the image was retrived from the local cache or from the network.
82 | * The fourth parameter is the original image url.
83 | */
84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
85 |
86 | /**
87 | * Set the imageView `image` with an `url`, placeholder and custom options.
88 | *
89 | * The download is asynchronous and cached.
90 | *
91 | * @param url The url for the image.
92 | * @param placeholder The image to be set initially, until the image request finishes.
93 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
94 | * @param completedBlock A block called when operation has been completed. This block has no return value
95 | * and takes the requested UIImage as first parameter. In case of error the image parameter
96 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
97 | * indicating if the image was retrived from the local cache or from the network.
98 | * The fourth parameter is the original image url.
99 | */
100 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
101 |
102 | /**
103 | * Cancel the current download
104 | */
105 | - (void)sd_cancelCurrentImageLoad;
106 |
107 | @end
108 |
109 |
110 | @interface MKAnnotationView (WebCacheDeprecated)
111 |
112 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
113 |
114 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
115 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
116 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`");
117 |
118 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
119 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
120 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
121 |
122 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
123 |
124 | @end
125 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageDownloader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 | #import "SDWebImageOperation.h"
12 |
13 | typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
14 | SDWebImageDownloaderLowPriority = 1 << 0,
15 | SDWebImageDownloaderProgressiveDownload = 1 << 1,
16 |
17 | /**
18 | * By default, request prevent the of NSURLCache. With this flag, NSURLCache
19 | * is used with default policies.
20 | */
21 | SDWebImageDownloaderUseNSURLCache = 1 << 2,
22 |
23 | /**
24 | * Call completion block with nil image/imageData if the image was read from NSURLCache
25 | * (to be combined with `SDWebImageDownloaderUseNSURLCache`).
26 | */
27 |
28 | SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,
29 | /**
30 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
31 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
32 | */
33 |
34 | SDWebImageDownloaderContinueInBackground = 1 << 4,
35 |
36 | /**
37 | * Handles cookies stored in NSHTTPCookieStore by setting
38 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
39 | */
40 | SDWebImageDownloaderHandleCookies = 1 << 5,
41 |
42 | /**
43 | * Enable to allow untrusted SSL ceriticates.
44 | * Useful for testing purposes. Use with caution in production.
45 | */
46 | SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
47 |
48 | /**
49 | * Put the image in the high priority queue.
50 | */
51 | SDWebImageDownloaderHighPriority = 1 << 7,
52 |
53 |
54 | };
55 |
56 | typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
57 | /**
58 | * Default value. All download operations will execute in queue style (first-in-first-out).
59 | */
60 | SDWebImageDownloaderFIFOExecutionOrder,
61 |
62 | /**
63 | * All download operations will execute in stack style (last-in-first-out).
64 | */
65 | SDWebImageDownloaderLIFOExecutionOrder
66 | };
67 |
68 | extern NSString *const SDWebImageDownloadStartNotification;
69 | extern NSString *const SDWebImageDownloadStopNotification;
70 |
71 | typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
72 |
73 | typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
74 |
75 | typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
76 |
77 | /**
78 | * Asynchronous downloader dedicated and optimized for image loading.
79 | */
80 | @interface SDWebImageDownloader : NSObject
81 |
82 | @property (assign, nonatomic) NSInteger maxConcurrentDownloads;
83 |
84 | /**
85 | * Shows the current amount of downloads that still need to be downloaded
86 | */
87 |
88 | @property (readonly, nonatomic) NSUInteger currentDownloadCount;
89 |
90 |
91 | /**
92 | * The timeout value (in seconds) for the download operation. Default: 15.0.
93 | */
94 | @property (assign, nonatomic) NSTimeInterval downloadTimeout;
95 |
96 |
97 | /**
98 | * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
99 | */
100 | @property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;
101 |
102 | /**
103 | * Singleton method, returns the shared instance
104 | *
105 | * @return global shared instance of downloader class
106 | */
107 | + (SDWebImageDownloader *)sharedDownloader;
108 |
109 | /**
110 | * Set username
111 | */
112 | @property (strong, nonatomic) NSString *username;
113 |
114 | /**
115 | * Set password
116 | */
117 | @property (strong, nonatomic) NSString *password;
118 |
119 | /**
120 | * Set filter to pick headers for downloading image HTTP request.
121 | *
122 | * This block will be invoked for each downloading image request, returned
123 | * NSDictionary will be used as headers in corresponding HTTP request.
124 | */
125 | @property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
126 |
127 | /**
128 | * Set a value for a HTTP header to be appended to each download HTTP request.
129 | *
130 | * @param value The value for the header field. Use `nil` value to remove the header.
131 | * @param field The name of the header field to set.
132 | */
133 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
134 |
135 | /**
136 | * Returns the value of the specified HTTP header field.
137 | *
138 | * @return The value associated with the header field field, or `nil` if there is no corresponding header field.
139 | */
140 | - (NSString *)valueForHTTPHeaderField:(NSString *)field;
141 |
142 | /**
143 | * Creates a SDWebImageDownloader async downloader instance with a given URL
144 | *
145 | * The delegate will be informed when the image is finish downloaded or an error has happen.
146 | *
147 | * @see SDWebImageDownloaderDelegate
148 | *
149 | * @param url The URL to the image to download
150 | * @param options The options to be used for this download
151 | * @param progressBlock A block called repeatedly while the image is downloading
152 | * @param completedBlock A block called once the download is completed.
153 | * If the download succeeded, the image parameter is set, in case of error,
154 | * error parameter is set with the error. The last parameter is always YES
155 | * if SDWebImageDownloaderProgressiveDownload isn't use. With the
156 | * SDWebImageDownloaderProgressiveDownload option, this block is called
157 | * repeatedly with the partial image object and the finished argument set to NO
158 | * before to be called a last time with the full image and finished argument
159 | * set to YES. In case of error, the finished argument is always YES.
160 | *
161 | * @return A cancellable SDWebImageOperation
162 | */
163 | - (id )downloadImageWithURL:(NSURL *)url
164 | options:(SDWebImageDownloaderOptions)options
165 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
166 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
167 |
168 | /**
169 | * Sets the download queue suspension state
170 | */
171 | - (void)setSuspended:(BOOL)suspended;
172 |
173 | @end
174 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTextData.m:
--------------------------------------------------------------------------------
1 | //
2 | // YMTextData.m
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/29.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | //
8 |
9 | #import "YMTextData.h"
10 | #import "ContantHead.h"
11 | #import "ILRegularExpressionManager.h"
12 | #import "NSString+NSString_ILExtension.h"
13 |
14 | #import "WFTextView.h"
15 |
16 | @implementation YMTextData{
17 |
18 | BOOL isReplyView;
19 | int tempInt;
20 | }
21 |
22 |
23 |
24 | - (id)init
25 | {
26 | self = [super init];
27 | if (self) {
28 |
29 | self.completionReplySource = [[NSMutableArray alloc] init];
30 | self.attributedData = [[NSMutableArray alloc] init];
31 | self.attributedDataWF = [[NSMutableArray alloc] init];
32 | self.showImageArray = [[NSMutableArray alloc] init];
33 | self.replyDataSource = [[NSMutableArray alloc] init];
34 | _foldOrNot = YES;
35 | _islessLimit = NO;
36 | _name = @"";
37 | _headPicURL = @"";
38 | _intro = @"";
39 | }
40 | return self;
41 | }
42 |
43 | //计算replyview高度
44 | - (float) calculateReplyHeightWithWidth:(float)sizeWidth{
45 |
46 |
47 | isReplyView = YES;
48 | float height = .0f;
49 | //NSLog(@" === %@",self.replyDataSource);
50 |
51 | for (int i = 0; i < self.replyDataSource.count; i ++ ) {
52 |
53 | tempInt = i;
54 |
55 | NSString *matchString = [self.replyDataSource objectAtIndex:i];
56 |
57 | NSArray *itemIndexs = [ILRegularExpressionManager itemIndexesWithPattern:EmotionItemPattern inString:matchString];
58 |
59 | NSString *newString = [matchString replaceCharactersAtIndexes:itemIndexs
60 | withString:PlaceHolder];
61 | //存新的
62 | [self.completionReplySource addObject:newString];
63 |
64 |
65 |
66 | [self matchString:newString fromView:isReplyView];
67 |
68 | WFTextView *_ilcoreText = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X,10, sizeWidth - offSet_X * 2, 0)];
69 |
70 | _ilcoreText.isDraw = NO;
71 |
72 | [_ilcoreText setOldString:[self.replyDataSource objectAtIndex:i] andNewString:newString];
73 |
74 | height = height + [_ilcoreText getTextHeight] + 5;
75 |
76 | }
77 |
78 | [self calculateShowImageHeight];
79 |
80 | return height;
81 |
82 | }
83 | //图片高度
84 | - (void)calculateShowImageHeight{
85 |
86 | if (self.showImageArray.count == 0) {
87 | self.showImageArray = 0;
88 | }else{
89 | self.showImageHeight = (ShowImage_H + 10) * ((self.showImageArray.count - 1)/3 + 1);
90 | }
91 |
92 | }
93 |
94 | - (void)matchString:(NSString *)dataSourceString fromView:(BOOL) isYMOrNot{
95 |
96 | if (isYMOrNot == YES) {
97 |
98 | NSMutableArray *totalArr = [NSMutableArray arrayWithCapacity:0];
99 |
100 | //**********号码******
101 |
102 | NSMutableArray *mobileLink = [ILRegularExpressionManager matchMobileLink:dataSourceString];
103 | for (int i = 0; i < mobileLink.count; i ++) {
104 |
105 | [totalArr addObject:[mobileLink objectAtIndex:i]];
106 | }
107 |
108 | //*************************
109 |
110 |
111 | //***********匹配网址*********
112 |
113 | NSMutableArray *webLink = [ILRegularExpressionManager matchWebLink:dataSourceString];
114 | for (int i = 0; i < webLink.count; i ++) {
115 |
116 | [totalArr addObject:[webLink objectAtIndex:i]];
117 | }
118 |
119 | //匹配姓名
120 | NSMutableArray *name = [ILRegularExpressionManager matchName:dataSourceString];
121 | for (int i = 0; i < name.count; i ++) {
122 |
123 | [totalArr addObject:[name objectAtIndex:i]];
124 | }
125 |
126 |
127 | //******自行添加**********
128 |
129 | if (_defineAttrData.count != 0) {
130 | NSArray *tArr = [_defineAttrData objectAtIndex:tempInt];
131 | for (int i = 0; i < [tArr count]; i ++) {
132 | NSString *string = [dataSourceString substringWithRange:NSRangeFromString([tArr objectAtIndex:i])];
133 | [totalArr addObject:[NSDictionary dictionaryWithObject:string forKey:NSStringFromRange(NSRangeFromString([tArr objectAtIndex:i]))]];
134 | }
135 |
136 | }
137 |
138 |
139 | //***********************
140 | [self.attributedData addObject:totalArr];
141 |
142 |
143 | }else{
144 |
145 | //**********号码******
146 |
147 | NSMutableArray *mobileLink = [ILRegularExpressionManager matchMobileLink:dataSourceString];
148 | for (int i = 0; i < mobileLink.count; i ++) {
149 |
150 | [self.attributedDataWF addObject:[mobileLink objectAtIndex:i]];
151 | }
152 |
153 | //*************************
154 |
155 |
156 | //***********匹配网址*********
157 |
158 | NSMutableArray *webLink = [ILRegularExpressionManager matchWebLink:dataSourceString];
159 | for (int i = 0; i < webLink.count; i ++) {
160 |
161 | [self.attributedDataWF addObject:[webLink objectAtIndex:i]];
162 | }
163 |
164 | //匹配姓名
165 | NSMutableArray *name = [ILRegularExpressionManager matchName:dataSourceString];
166 | for (int i = 0; i < name.count; i ++) {
167 |
168 | [self.attributedDataWF addObject:[name objectAtIndex:i]];
169 | }
170 |
171 | //******自行添加**********
172 | // NSString *string = [dataSourceString substringWithRange:NSMakeRange(0, 3)];
173 | // [self.attributedDataWF addObject:[NSDictionary dictionaryWithObject:string forKey:NSStringFromRange(NSMakeRange(0, 3))]];
174 | //**********************
175 | }
176 |
177 |
178 | }
179 |
180 | //说说高度
181 | - (float) calculateShuoshuoHeightWithWidth:(float)sizeWidth withUnFoldState:(BOOL)isUnfold{
182 |
183 | isReplyView = NO;
184 |
185 | NSString *matchString = _showShuoShuo;
186 |
187 | NSArray *itemIndexs = [ILRegularExpressionManager itemIndexesWithPattern:EmotionItemPattern inString:matchString];
188 |
189 | NSString *newString = [matchString replaceCharactersAtIndexes:itemIndexs
190 | withString:PlaceHolder];
191 | //存新的
192 | self.completionShuoshuo = newString;
193 |
194 | [self matchString:newString fromView:isReplyView];
195 |
196 | WFTextView *_wfcoreText = [[WFTextView alloc] initWithFrame:CGRectMake(20,10, sizeWidth - 2*20, 0)];
197 |
198 | _wfcoreText.isDraw = NO;
199 |
200 | [_wfcoreText setOldString:_showShuoShuo andNewString:newString];
201 |
202 | if ([_wfcoreText getTextLines] <= limitline) {
203 | self.islessLimit = YES;
204 | }else{
205 | self.islessLimit = NO;
206 | }
207 |
208 | if (!isUnfold) {
209 |
210 | _wfcoreText.isFold = YES;
211 |
212 | }else{
213 |
214 | _wfcoreText.isFold = NO;
215 |
216 |
217 | }
218 | return [_wfcoreText getTextHeight];
219 |
220 |
221 | }
222 |
223 |
224 | @end
225 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDImageCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 |
12 | typedef NS_ENUM(NSInteger, SDImageCacheType) {
13 | /**
14 | * The image wasn't available the SDWebImage caches, but was downloaded from the web.
15 | */
16 | SDImageCacheTypeNone,
17 | /**
18 | * The image was obtained from the disk cache.
19 | */
20 | SDImageCacheTypeDisk,
21 | /**
22 | * The image was obtained from the memory cache.
23 | */
24 | SDImageCacheTypeMemory
25 | };
26 |
27 | typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType);
28 |
29 | typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
30 |
31 | typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
32 |
33 | /**
34 | * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
35 | * asynchronous so it doesn’t add unnecessary latency to the UI.
36 | */
37 | @interface SDImageCache : NSObject
38 |
39 | /**
40 | * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
41 | */
42 | @property (assign, nonatomic) NSUInteger maxMemoryCost;
43 |
44 | /**
45 | * The maximum length of time to keep an image in the cache, in seconds
46 | */
47 | @property (assign, nonatomic) NSInteger maxCacheAge;
48 |
49 | /**
50 | * The maximum size of the cache, in bytes.
51 | */
52 | @property (assign, nonatomic) NSUInteger maxCacheSize;
53 |
54 | /**
55 | * Returns global shared cache instance
56 | *
57 | * @return SDImageCache global instance
58 | */
59 | + (SDImageCache *)sharedImageCache;
60 |
61 | /**
62 | * Init a new cache store with a specific namespace
63 | *
64 | * @param ns The namespace to use for this cache store
65 | */
66 | - (id)initWithNamespace:(NSString *)ns;
67 |
68 | /**
69 | * Add a read-only cache path to search for images pre-cached by SDImageCache
70 | * Useful if you want to bundle pre-loaded images with your app
71 | *
72 | * @param path The path to use for this read-only cache path
73 | */
74 | - (void)addReadOnlyCachePath:(NSString *)path;
75 |
76 | /**
77 | * Store an image into memory and disk cache at the given key.
78 | *
79 | * @param image The image to store
80 | * @param key The unique image cache key, usually it's image absolute URL
81 | */
82 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key;
83 |
84 | /**
85 | * Store an image into memory and optionally disk cache at the given key.
86 | *
87 | * @param image The image to store
88 | * @param key The unique image cache key, usually it's image absolute URL
89 | * @param toDisk Store the image to disk cache if YES
90 | */
91 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
92 |
93 | /**
94 | * Store an image into memory and optionally disk cache at the given key.
95 | *
96 | * @param image The image to store
97 | * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
98 | * @param imageData The image data as returned by the server, this representation will be used for disk storage
99 | * instead of converting the given image object into a storable/compressed image format in order
100 | * to save quality and CPU
101 | * @param key The unique image cache key, usually it's image absolute URL
102 | * @param toDisk Store the image to disk cache if YES
103 | */
104 | - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
105 |
106 | /**
107 | * Query the disk cache asynchronously.
108 | *
109 | * @param key The unique key used to store the wanted image
110 | */
111 | - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
112 |
113 | /**
114 | * Query the memory cache synchronously.
115 | *
116 | * @param key The unique key used to store the wanted image
117 | */
118 | - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key;
119 |
120 | /**
121 | * Query the disk cache synchronously after checking the memory cache.
122 | *
123 | * @param key The unique key used to store the wanted image
124 | */
125 | - (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
126 |
127 | /**
128 | * Remove the image from memory and disk cache synchronously
129 | *
130 | * @param key The unique image cache key
131 | */
132 | - (void)removeImageForKey:(NSString *)key;
133 |
134 |
135 | /**
136 | * Remove the image from memory and disk cache synchronously
137 | *
138 | * @param key The unique image cache key
139 | * @param completion An block that should be executed after the image has been removed (optional)
140 | */
141 | - (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
142 |
143 | /**
144 | * Remove the image from memory and optionally disk cache synchronously
145 | *
146 | * @param key The unique image cache key
147 | * @param fromDisk Also remove cache entry from disk if YES
148 | */
149 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
150 |
151 | /**
152 | * Remove the image from memory and optionally disk cache synchronously
153 | *
154 | * @param key The unique image cache key
155 | * @param fromDisk Also remove cache entry from disk if YES
156 | * @param completion An block that should be executed after the image has been removed (optional)
157 | */
158 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
159 |
160 | /**
161 | * Clear all memory cached images
162 | */
163 | - (void)clearMemory;
164 |
165 | /**
166 | * Clear all disk cached images. Non-blocking method - returns immediately.
167 | * @param completion An block that should be executed after cache expiration completes (optional)
168 | */
169 | - (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
170 |
171 | /**
172 | * Clear all disk cached images
173 | * @see clearDiskOnCompletion:
174 | */
175 | - (void)clearDisk;
176 |
177 | /**
178 | * Remove all expired cached image from disk. Non-blocking method - returns immediately.
179 | * @param completionBlock An block that should be executed after cache expiration completes (optional)
180 | */
181 | - (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
182 |
183 | /**
184 | * Remove all expired cached image from disk
185 | * @see cleanDiskWithCompletionBlock:
186 | */
187 | - (void)cleanDisk;
188 |
189 | /**
190 | * Get the size used by the disk cache
191 | */
192 | - (NSUInteger)getSize;
193 |
194 | /**
195 | * Get the number of images in the disk cache
196 | */
197 | - (NSUInteger)getDiskCount;
198 |
199 | /**
200 | * Asynchronously calculate the disk cache's size.
201 | */
202 | - (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
203 |
204 | /**
205 | * Async check if image exists in disk cache already (does not load the image)
206 | *
207 | * @param key the key describing the url
208 | * @param completionBlock the block to be executed when the check is done.
209 | * @note the completion block will be always executed on the main queue
210 | */
211 | - (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
212 |
213 | /**
214 | * Check if image exists in disk cache already (does not load the image)
215 | *
216 | * @param key the key describing the url
217 | *
218 | * @return YES if an image exists for the given key
219 | */
220 | - (BOOL)diskImageExistsWithKey:(NSString *)key;
221 |
222 | /**
223 | * Get the cache path for a certain key (needs the cache path root folder)
224 | *
225 | * @param key the key (can be obtained from url using cacheKeyForURL)
226 | * @param path the cach path root folder
227 | *
228 | * @return the cache path
229 | */
230 | - (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;
231 |
232 | /**
233 | * Get the default cache path for a certain key
234 | *
235 | * @param key the key (can be obtained from url using cacheKeyForURL)
236 | *
237 | * @return the default cache path
238 | */
239 | - (NSString *)defaultCachePathForKey:(NSString *)key;
240 |
241 | @end
242 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImageView+WebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIImageView+WebCache.h"
10 | #import "objc/runtime.h"
11 | #import "UIView+WebCacheOperation.h"
12 |
13 | static char imageURLKey;
14 |
15 | @implementation UIImageView (WebCache)
16 |
17 | - (void)sd_setImageWithURL:(NSURL *)url {
18 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
19 | }
20 |
21 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
22 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
23 | }
24 |
25 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
26 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
27 | }
28 |
29 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
30 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
31 | }
32 |
33 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
34 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
35 | }
36 |
37 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
38 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
39 | }
40 |
41 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
42 | [self sd_cancelCurrentImageLoad];
43 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
44 |
45 | if (!(options & SDWebImageDelayPlaceholder)) {
46 | dispatch_main_async_safe(^{
47 | self.image = placeholder;
48 | });
49 | }
50 |
51 | if (url) {
52 | __weak UIImageView *wself = self;
53 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
54 | if (!wself) return;
55 | dispatch_main_sync_safe(^{
56 | if (!wself) return;
57 | if (image) {
58 | wself.image = image;
59 | [wself setNeedsLayout];
60 | } else {
61 | if ((options & SDWebImageDelayPlaceholder)) {
62 | wself.image = placeholder;
63 | [wself setNeedsLayout];
64 | }
65 | }
66 | if (completedBlock && finished) {
67 | completedBlock(image, error, cacheType, url);
68 | }
69 | });
70 | }];
71 | [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
72 | } else {
73 | dispatch_main_async_safe(^{
74 | NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
75 | if (completedBlock) {
76 | completedBlock(nil, error, SDImageCacheTypeNone, url);
77 | }
78 | });
79 | }
80 | }
81 |
82 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
83 | NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
84 | UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
85 |
86 | [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
87 | }
88 |
89 | - (NSURL *)sd_imageURL {
90 | return objc_getAssociatedObject(self, &imageURLKey);
91 | }
92 |
93 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
94 | [self sd_cancelCurrentAnimationImagesLoad];
95 | __weak UIImageView *wself = self;
96 |
97 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
98 |
99 | for (NSURL *logoImageURL in arrayOfURLs) {
100 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
101 | if (!wself) return;
102 | dispatch_main_sync_safe(^{
103 | __strong UIImageView *sself = wself;
104 | [sself stopAnimating];
105 | if (sself && image) {
106 | NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
107 | if (!currentImages) {
108 | currentImages = [[NSMutableArray alloc] init];
109 | }
110 | [currentImages addObject:image];
111 |
112 | sself.animationImages = currentImages;
113 | [sself setNeedsLayout];
114 | }
115 | [sself startAnimating];
116 | });
117 | }];
118 | [operationsArray addObject:operation];
119 | }
120 |
121 | [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"];
122 | }
123 |
124 | - (void)sd_cancelCurrentImageLoad {
125 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"];
126 | }
127 |
128 | - (void)sd_cancelCurrentAnimationImagesLoad {
129 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
130 | }
131 |
132 | @end
133 |
134 |
135 | @implementation UIImageView (WebCacheDeprecated)
136 |
137 | - (NSURL *)imageURL {
138 | return [self sd_imageURL];
139 | }
140 |
141 | - (void)setImageWithURL:(NSURL *)url {
142 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
143 | }
144 |
145 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
146 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
147 | }
148 |
149 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
150 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
151 | }
152 |
153 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
154 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
155 | if (completedBlock) {
156 | completedBlock(image, error, cacheType);
157 | }
158 | }];
159 | }
160 |
161 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
162 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
163 | if (completedBlock) {
164 | completedBlock(image, error, cacheType);
165 | }
166 | }];
167 | }
168 |
169 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
170 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
171 | if (completedBlock) {
172 | completedBlock(image, error, cacheType);
173 | }
174 | }];
175 | }
176 |
177 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
178 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
179 | if (completedBlock) {
180 | completedBlock(image, error, cacheType);
181 | }
182 | }];
183 | }
184 |
185 | - (void)cancelCurrentArrayLoad {
186 | [self sd_cancelCurrentAnimationImagesLoad];
187 | }
188 |
189 | - (void)cancelCurrentImageLoad {
190 | [self sd_cancelCurrentImageLoad];
191 | }
192 |
193 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
194 | [self sd_setAnimationImagesWithURLs:arrayOfURLs];
195 | }
196 |
197 | @end
198 |
--------------------------------------------------------------------------------
/DDRichTextLib/DDRichTextViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // DDRichTextViewController.m
3 | // WFCoretext
4 | //
5 | // Created by David on 15/2/6.
6 | // Copyright (c) 2015年 tigerwf. All rights reserved.
7 | //
8 | #import "UIImageView+WebCache.h"
9 | #import "DDRichTextViewController.h"
10 |
11 | @interface DDRichTextViewController()
12 | {
13 | UITableView *mainTable;
14 | UIButton *replyBtn;
15 | YMReplyInputView *replyView ;
16 | BOOL hideReply;
17 | }
18 | @end
19 |
20 | @implementation DDRichTextViewController
21 |
22 | - (void)viewDidLoad {
23 | [super viewDidLoad];
24 | self.view.backgroundColor = [UIColor whiteColor];
25 | [self initTableview];
26 | }
27 |
28 | #pragma mark - 计算高度
29 | - (YMTextData*)calculateHeights:(YMTextData *)ymData{
30 | ymData.shuoshuoHeight = [ymData calculateShuoshuoHeightWithWidth:self.view.frame.size.width withUnFoldState:NO];//折叠
31 | ymData.unFoldShuoHeight = [ymData calculateShuoshuoHeightWithWidth:self.view.frame.size.width withUnFoldState:YES];//展开
32 | ymData.replyHeight = [ymData calculateReplyHeightWithWidth:self.view.frame.size.width];
33 | return ymData;
34 | }
35 |
36 |
37 | - (void) initTableview{
38 | mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
39 | mainTable.backgroundColor = [UIColor groupTableViewBackgroundColor];
40 | mainTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
41 | mainTable.delegate = self;
42 | mainTable.dataSource = self;
43 | [self.view addSubview:mainTable];
44 | }
45 |
46 | -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
47 | return 5;
48 | }
49 |
50 | -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
51 | return 5;
52 | }
53 |
54 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
55 | return [[self dataSource] numberOfRowsInDDRichText];
56 | }
57 |
58 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
59 | return 1;
60 | }
61 |
62 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
63 |
64 | YMTextData *ym = [self calculateHeights:[[self dataSource] dataForRowAtIndex:[indexPath section]]];
65 | BOOL unfold = ym.foldOrNot;
66 | CGFloat height = TableHeader + kLocationToBottom + ym.replyHeight + ym.showImageHeight + kDistance + (ym.islessLimit?0:30) + (unfold?ym.shuoshuoHeight:ym.unFoldShuoHeight) + kReplyBtnDistance;
67 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"hideReplyButtonForIndex:")]) {
68 | if ([[self delegate] hideReplyButtonForIndex:indexPath.section]) {
69 | height -= 40;
70 | }
71 | }
72 | return height;
73 | }
74 |
75 |
76 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
77 | static NSString *CellIdentifier = @"ILTableViewCell";
78 | YMTableViewCell *cell = (YMTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
79 | if (cell == nil) {
80 | cell = [[YMTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
81 | }
82 | cell.stamp = indexPath.section;
83 | cell.replyBtn.tag = indexPath.section;
84 | cell.replyBtn.appendIndexPath = indexPath;
85 | [cell.replyBtn addTarget:self action:@selector(replyAction:) forControlEvents:UIControlEventTouchUpInside];
86 | cell.delegate = self;
87 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"hideReplyButtonForIndex:")]) {
88 | if ([[self delegate] hideReplyButtonForIndex:indexPath.section]) {
89 | cell.hideReply = YES;
90 | }
91 | }
92 | YMTextData *data = [[self dataSource] dataForRowAtIndex:[indexPath section]];
93 | //这句话让头像 支持异步加载
94 | [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:data.headPicURL] placeholderImage:[UIImage imageNamed:@"nilPic.png"]];
95 | // cell.headerImage.image = data.headPic;
96 | cell.nameLbl.text = data.name;
97 | cell.introLbl.text = data.intro;
98 | [cell setYMViewWith:data];
99 | return cell;
100 | }
101 |
102 | -(void)haha{
103 | NSLog(@"hehe");
104 | }
105 |
106 | #pragma mark - 按钮动画
107 |
108 | - (void)replyAction:(YMButton *)sender{
109 | CGRect rectInTableView = [mainTable rectForRowAtIndexPath:sender.appendIndexPath];
110 | float origin_Y = rectInTableView.origin.y + sender.frame.origin.y;
111 | if (replyBtn) {
112 | [UIView animateWithDuration:0.25f animations:^{
113 | replyBtn.frame = CGRectMake(sender.frame.origin.x, origin_Y - 10 , 0, 38);
114 | } completion:^(BOOL finished) {
115 | NSLog(@"销毁");
116 | [replyBtn removeFromSuperview];
117 | replyBtn = nil;
118 | }];
119 | }else{
120 | replyBtn = [UIButton buttonWithType:0];
121 | replyBtn.layer.cornerRadius = 5;
122 | replyBtn.backgroundColor = [UIColor colorWithRed:33/255.0 green:37/255.0 blue:38/255.0 alpha:0.8];
123 | replyBtn.frame = CGRectMake(sender.frame.origin.x , origin_Y - 10 , 0, 38);
124 | [replyBtn setTitleColor:[UIColor whiteColor] forState:0];
125 | replyBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
126 | replyBtn.tag = sender.tag;
127 | [mainTable addSubview:replyBtn];
128 | [replyBtn addTarget:self action:@selector(replyMessage:) forControlEvents:UIControlEventTouchUpInside];
129 | [UIView animateWithDuration:0.25f animations:^{
130 | replyBtn.frame = CGRectMake(sender.frame.origin.x - 60, origin_Y - 10 , 60, 38);
131 | } completion:^(BOOL finished) {
132 | [replyBtn setTitle:@"评论" forState:0];
133 | }];
134 | }
135 | }
136 |
137 | #pragma mark - 真の评论
138 | - (void)replyMessage:(UIButton *)sender{
139 | //NSLog(@"TAG === %d",sender.tag);
140 | if (replyBtn){
141 | [replyBtn removeFromSuperview];
142 | replyBtn = nil;
143 | }
144 | // NSLog(@"alloc reply");
145 |
146 | replyView = [[YMReplyInputView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, screenWidth,44) andAboveView:self.view];
147 | replyView.delegate = self;
148 | replyView.replyTag = sender.tag;
149 | [self.view addSubview:replyView];
150 | }
151 |
152 |
153 | #pragma mark -移除评论按钮
154 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
155 |
156 | if (replyBtn) {
157 | [replyBtn removeFromSuperview];
158 | replyBtn = nil;
159 | }
160 | }
161 |
162 |
163 | #pragma mark -cellDelegate
164 | - (void)changeFoldState:(YMTextData *)ymD onCellRow:(NSInteger)cellStamp{
165 | YMTableViewCell *cell = (YMTableViewCell*)[mainTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:cellStamp]];
166 | [cell setYMViewWith:ymD];
167 | [mainTable reloadData];
168 | }
169 |
170 | -(void)didHeadPicPressForIndex:(NSInteger)index{
171 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didPromulgatorPressForIndex:name:")]) {
172 | [self.delegate didPromulgatorPressForIndex:index name:@""];
173 | }
174 | }
175 |
176 | -(void)didPromulgatorNameOrHeadPicPressedForIndex:(NSInteger)index name:(NSString *)name{
177 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didPromulgatorPressForIndex:name:")]) {
178 | [self.delegate didPromulgatorPressForIndex:index name:name];
179 | }
180 | }
181 |
182 | -(void)didRichTextPress:(NSString *)text index:(NSInteger)index{
183 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didRichTextPressedFromText:index:")]) {
184 | [self.delegate didRichTextPressedFromText:text index:index];
185 | }
186 | }
187 |
188 | -(void)didRichTextPress:(NSString *)text index:(NSInteger)index replyIndex:(NSInteger)replyIndex{
189 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didRichTextPressedFromText:index:replyIndex:")]) {
190 | [self.delegate didRichTextPressedFromText:text index:index replyIndex:replyIndex];
191 | }
192 | }
193 |
194 | #pragma mark - 图片点击事件回调
195 | - (void)showImageViewWithImageViews:(NSArray *)imageViews byClickWhich:(NSInteger)clickTag{
196 | [[self navigationController] setNavigationBarHidden:YES animated:YES];
197 | UIView *maskview = [[UIView alloc] initWithFrame:self.view.bounds];
198 | maskview.backgroundColor = [UIColor blackColor];
199 | [self.view addSubview:maskview];
200 | YMShowImageView *ymImageV = [[YMShowImageView alloc] initWithFrame:self.view.bounds byClick:clickTag appendArray:imageViews];
201 | [ymImageV show:maskview didFinish:^(){
202 | [[self navigationController] setNavigationBarHidden:NO animated:YES];
203 | [UIView animateWithDuration:0.5f animations:^{
204 | ymImageV.alpha = 0.0f;
205 | maskview.alpha = 0.0f;
206 | } completion:^(BOOL finished) {
207 | [ymImageV removeFromSuperview];
208 | [maskview removeFromSuperview];
209 | }];
210 |
211 | }];
212 | }
213 |
214 | #pragma mark - 评论说说回调
215 | - (void)YMReplyInputWithReply:(NSString *)replyText appendTag:(NSInteger)inputTag{
216 | NSLog(@"评论说说回调");
217 |
218 | NSString *newString = [NSString stringWithFormat:@"@%@:%@",[[self delegate] senderName],replyText];//此处可扩展。已写死,包括内部逻辑也写死 在YMTextData里 自行添加部分
219 | YMTableViewCell *cell = (YMTableViewCell*)[mainTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:inputTag]];
220 | YMTextData *ymData = [cell getYMTextData];
221 | [ymData.replyDataSource addObject:newString];
222 | //清空属性数组。否则会重复添加
223 | [ymData.completionReplySource removeAllObjects];
224 | [ymData.attributedData removeAllObjects];
225 |
226 | NSString *rangeStr = NSStringFromRange(NSMakeRange(0, [[self delegate] senderName].length));
227 | NSMutableArray *rangeArr = [[NSMutableArray alloc] init];
228 | [rangeArr addObject:rangeStr];
229 | [ymData.defineAttrData addObject:rangeArr];
230 | ymData.replyHeight = [ymData calculateReplyHeightWithWidth:self.view.frame.size.width];
231 | [cell setYMViewWith:ymData];
232 | [mainTable reloadData];
233 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"replyForIndex:replyText:")]) {
234 | [self.delegate replyForIndex:inputTag replyText:replyText];
235 | }
236 |
237 | }
238 |
239 | - (void)destorySelf{
240 | // NSLog(@"dealloc reply");
241 | [replyView removeFromSuperview];
242 | replyView = nil;
243 | }
244 |
245 |
246 | - (void)dealloc{
247 |
248 | }
249 |
250 |
251 |
252 | @end
253 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIImageView+WebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageCompat.h"
10 | #import "SDWebImageManager.h"
11 |
12 | /**
13 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView.
14 | *
15 | * Usage with a UITableViewCell sub-class:
16 | *
17 | * @code
18 |
19 | #import
20 |
21 | ...
22 |
23 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
24 | {
25 | static NSString *MyIdentifier = @"MyIdentifier";
26 |
27 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
28 |
29 | if (cell == nil) {
30 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
31 | autorelease];
32 | }
33 |
34 | // Here we use the provided sd_setImageWithURL: method to load the web image
35 | // Ensure you use a placeholder image otherwise cells will be initialized with no image
36 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
37 | placeholderImage:[UIImage imageNamed:@"placeholder"]];
38 |
39 | cell.textLabel.text = @"My Text";
40 | return cell;
41 | }
42 |
43 | * @endcode
44 | */
45 | @interface UIImageView (WebCache)
46 |
47 | /**
48 | * Get the current image URL.
49 | *
50 | * Note that because of the limitations of categories this property can get out of sync
51 | * if you use sd_setImage: directly.
52 | */
53 | - (NSURL *)sd_imageURL;
54 |
55 | /**
56 | * Set the imageView `image` with an `url`.
57 | *
58 | * The download is asynchronous and cached.
59 | *
60 | * @param url The url for the image.
61 | */
62 | - (void)sd_setImageWithURL:(NSURL *)url;
63 |
64 | /**
65 | * Set the imageView `image` with an `url` and a placeholder.
66 | *
67 | * The download is asynchronous and cached.
68 | *
69 | * @param url The url for the image.
70 | * @param placeholder The image to be set initially, until the image request finishes.
71 | * @see sd_setImageWithURL:placeholderImage:options:
72 | */
73 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
74 |
75 | /**
76 | * Set the imageView `image` with an `url`, placeholder and custom options.
77 | *
78 | * The download is asynchronous and cached.
79 | *
80 | * @param url The url for the image.
81 | * @param placeholder The image to be set initially, until the image request finishes.
82 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
83 | */
84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
85 |
86 | /**
87 | * Set the imageView `image` with an `url`.
88 | *
89 | * The download is asynchronous and cached.
90 | *
91 | * @param url The url for the image.
92 | * @param completedBlock A block called when operation has been completed. This block has no return value
93 | * and takes the requested UIImage as first parameter. In case of error the image parameter
94 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
95 | * indicating if the image was retrived from the local cache or from the network.
96 | * The fourth parameter is the original image url.
97 | */
98 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
99 |
100 | /**
101 | * Set the imageView `image` with an `url`, placeholder.
102 | *
103 | * The download is asynchronous and cached.
104 | *
105 | * @param url The url for the image.
106 | * @param placeholder The image to be set initially, until the image request finishes.
107 | * @param completedBlock A block called when operation has been completed. This block has no return value
108 | * and takes the requested UIImage as first parameter. In case of error the image parameter
109 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
110 | * indicating if the image was retrived from the local cache or from the network.
111 | * The fourth parameter is the original image url.
112 | */
113 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
114 |
115 | /**
116 | * Set the imageView `image` with an `url`, placeholder and custom options.
117 | *
118 | * The download is asynchronous and cached.
119 | *
120 | * @param url The url for the image.
121 | * @param placeholder The image to be set initially, until the image request finishes.
122 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
123 | * @param completedBlock A block called when operation has been completed. This block has no return value
124 | * and takes the requested UIImage as first parameter. In case of error the image parameter
125 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
126 | * indicating if the image was retrived from the local cache or from the network.
127 | * The fourth parameter is the original image url.
128 | */
129 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
130 |
131 | /**
132 | * Set the imageView `image` with an `url`, placeholder and custom options.
133 | *
134 | * The download is asynchronous and cached.
135 | *
136 | * @param url The url for the image.
137 | * @param placeholder The image to be set initially, until the image request finishes.
138 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
139 | * @param progressBlock A block called while image is downloading
140 | * @param completedBlock A block called when operation has been completed. This block has no return value
141 | * and takes the requested UIImage as first parameter. In case of error the image parameter
142 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
143 | * indicating if the image was retrived from the local cache or from the network.
144 | * The fourth parameter is the original image url.
145 | */
146 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
147 |
148 | /**
149 | * Set the imageView `image` with an `url` and a optionaly placeholder image.
150 | *
151 | * The download is asynchronous and cached.
152 | *
153 | * @param url The url for the image.
154 | * @param placeholder The image to be set initially, until the image request finishes.
155 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
156 | * @param progressBlock A block called while image is downloading
157 | * @param completedBlock A block called when operation has been completed. This block has no return value
158 | * and takes the requested UIImage as first parameter. In case of error the image parameter
159 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
160 | * indicating if the image was retrived from the local cache or from the network.
161 | * The fourth parameter is the original image url.
162 | */
163 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
164 |
165 | /**
166 | * Download an array of images and starts them in an animation loop
167 | *
168 | * @param arrayOfURLs An array of NSURL
169 | */
170 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
171 |
172 | /**
173 | * Cancel the current download
174 | */
175 | - (void)sd_cancelCurrentImageLoad;
176 |
177 | - (void)sd_cancelCurrentAnimationImagesLoad;
178 |
179 | @end
180 |
181 |
182 | @interface UIImageView (WebCacheDeprecated)
183 |
184 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
185 |
186 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
187 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
188 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
189 |
190 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
191 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
192 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
193 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`");
194 |
195 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`");
196 |
197 | - (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`");
198 |
199 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
200 |
201 | @end
202 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageDownloader.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageDownloader.h"
10 | #import "SDWebImageDownloaderOperation.h"
11 | #import
12 |
13 | NSString *const SDWebImageDownloadStartNotification = @"SDWebImageDownloadStartNotification";
14 | NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNotification";
15 |
16 | static NSString *const kProgressCallbackKey = @"progress";
17 | static NSString *const kCompletedCallbackKey = @"completed";
18 |
19 | @interface SDWebImageDownloader ()
20 |
21 | @property (strong, nonatomic) NSOperationQueue *downloadQueue;
22 | @property (weak, nonatomic) NSOperation *lastAddedOperation;
23 | @property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
24 | @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
25 | // This queue is used to serialize the handling of the network responses of all the download operation in a single queue
26 | @property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
27 |
28 | @end
29 |
30 | @implementation SDWebImageDownloader
31 |
32 | + (void)initialize {
33 | // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator )
34 | // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import
35 | if (NSClassFromString(@"SDNetworkActivityIndicator")) {
36 |
37 | #pragma clang diagnostic push
38 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
39 | id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")];
40 | #pragma clang diagnostic pop
41 |
42 | // Remove observer in case it was previously added.
43 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil];
44 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil];
45 |
46 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
47 | selector:NSSelectorFromString(@"startActivity")
48 | name:SDWebImageDownloadStartNotification object:nil];
49 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
50 | selector:NSSelectorFromString(@"stopActivity")
51 | name:SDWebImageDownloadStopNotification object:nil];
52 | }
53 | }
54 |
55 | + (SDWebImageDownloader *)sharedDownloader {
56 | static dispatch_once_t once;
57 | static id instance;
58 | dispatch_once(&once, ^{
59 | instance = [self new];
60 | });
61 | return instance;
62 | }
63 |
64 | - (id)init {
65 | if ((self = [super init])) {
66 | _executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
67 | _downloadQueue = [NSOperationQueue new];
68 | _downloadQueue.maxConcurrentOperationCount = 2;
69 | _URLCallbacks = [NSMutableDictionary new];
70 | _HTTPHeaders = [NSMutableDictionary dictionaryWithObject:@"image/webp,image/*;q=0.8" forKey:@"Accept"];
71 | _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
72 | _downloadTimeout = 15.0;
73 | }
74 | return self;
75 | }
76 |
77 | - (void)dealloc {
78 | [self.downloadQueue cancelAllOperations];
79 | SDDispatchQueueRelease(_barrierQueue);
80 | }
81 |
82 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field {
83 | if (value) {
84 | self.HTTPHeaders[field] = value;
85 | }
86 | else {
87 | [self.HTTPHeaders removeObjectForKey:field];
88 | }
89 | }
90 |
91 | - (NSString *)valueForHTTPHeaderField:(NSString *)field {
92 | return self.HTTPHeaders[field];
93 | }
94 |
95 | - (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads {
96 | _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads;
97 | }
98 |
99 | - (NSUInteger)currentDownloadCount {
100 | return _downloadQueue.operationCount;
101 | }
102 |
103 | - (NSInteger)maxConcurrentDownloads {
104 | return _downloadQueue.maxConcurrentOperationCount;
105 | }
106 |
107 | - (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
108 | __block SDWebImageDownloaderOperation *operation;
109 | __weak SDWebImageDownloader *wself = self;
110 |
111 | [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
112 | NSTimeInterval timeoutInterval = wself.downloadTimeout;
113 | if (timeoutInterval == 0.0) {
114 | timeoutInterval = 15.0;
115 | }
116 |
117 | // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
118 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
119 | request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
120 | request.HTTPShouldUsePipelining = YES;
121 | if (wself.headersFilter) {
122 | request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
123 | }
124 | else {
125 | request.allHTTPHeaderFields = wself.HTTPHeaders;
126 | }
127 | operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
128 | options:options
129 | progress:^(NSInteger receivedSize, NSInteger expectedSize) {
130 | SDWebImageDownloader *sself = wself;
131 | if (!sself) return;
132 | NSArray *callbacksForURL = [sself callbacksForURL:url];
133 | for (NSDictionary *callbacks in callbacksForURL) {
134 | SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
135 | if (callback) callback(receivedSize, expectedSize);
136 | }
137 | }
138 | completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
139 | SDWebImageDownloader *sself = wself;
140 | if (!sself) return;
141 | NSArray *callbacksForURL = [sself callbacksForURL:url];
142 | if (finished) {
143 | [sself removeCallbacksForURL:url];
144 | }
145 | for (NSDictionary *callbacks in callbacksForURL) {
146 | SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
147 | if (callback) callback(image, data, error, finished);
148 | }
149 | }
150 | cancelled:^{
151 | SDWebImageDownloader *sself = wself;
152 | if (!sself) return;
153 | [sself removeCallbacksForURL:url];
154 | }];
155 |
156 | if (wself.username && wself.password) {
157 | operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
158 | }
159 |
160 | if (options & SDWebImageDownloaderHighPriority) {
161 | operation.queuePriority = NSOperationQueuePriorityHigh;
162 | } else if (options & SDWebImageDownloaderLowPriority) {
163 | operation.queuePriority = NSOperationQueuePriorityLow;
164 | }
165 |
166 | [wself.downloadQueue addOperation:operation];
167 | if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
168 | // Emulate LIFO execution order by systematically adding new operations as last operation's dependency
169 | [wself.lastAddedOperation addDependency:operation];
170 | wself.lastAddedOperation = operation;
171 | }
172 | }];
173 |
174 | return operation;
175 | }
176 |
177 | - (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock andCompletedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
178 | // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
179 | if (url == nil) {
180 | if (completedBlock != nil) {
181 | completedBlock(nil, nil, nil, NO);
182 | }
183 | return;
184 | }
185 |
186 | dispatch_barrier_sync(self.barrierQueue, ^{
187 | BOOL first = NO;
188 | if (!self.URLCallbacks[url]) {
189 | self.URLCallbacks[url] = [NSMutableArray new];
190 | first = YES;
191 | }
192 |
193 | // Handle single download of simultaneous download request for the same URL
194 | NSMutableArray *callbacksForURL = self.URLCallbacks[url];
195 | NSMutableDictionary *callbacks = [NSMutableDictionary new];
196 | if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
197 | if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
198 | [callbacksForURL addObject:callbacks];
199 | self.URLCallbacks[url] = callbacksForURL;
200 |
201 | if (first) {
202 | createCallback();
203 | }
204 | });
205 | }
206 |
207 | - (NSArray *)callbacksForURL:(NSURL *)url {
208 | __block NSArray *callbacksForURL;
209 | dispatch_sync(self.barrierQueue, ^{
210 | callbacksForURL = self.URLCallbacks[url];
211 | });
212 | return [callbacksForURL copy];
213 | }
214 |
215 | - (void)removeCallbacksForURL:(NSURL *)url {
216 | dispatch_barrier_async(self.barrierQueue, ^{
217 | [self.URLCallbacks removeObjectForKey:url];
218 | });
219 | }
220 |
221 | - (void)setSuspended:(BOOL)suspended {
222 | [self.downloadQueue setSuspended:suspended];
223 | }
224 |
225 | @end
226 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/SDWebImageManager.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageCompat.h"
10 | #import "SDWebImageOperation.h"
11 | #import "SDWebImageDownloader.h"
12 | #import "SDImageCache.h"
13 |
14 | typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
15 | /**
16 | * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
17 | * This flag disable this blacklisting.
18 | */
19 | SDWebImageRetryFailed = 1 << 0,
20 |
21 | /**
22 | * By default, image downloads are started during UI interactions, this flags disable this feature,
23 | * leading to delayed download on UIScrollView deceleration for instance.
24 | */
25 | SDWebImageLowPriority = 1 << 1,
26 |
27 | /**
28 | * This flag disables on-disk caching
29 | */
30 | SDWebImageCacheMemoryOnly = 1 << 2,
31 |
32 | /**
33 | * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
34 | * By default, the image is only displayed once completely downloaded.
35 | */
36 | SDWebImageProgressiveDownload = 1 << 3,
37 |
38 | /**
39 | * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
40 | * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
41 | * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
42 | * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
43 | *
44 | * Use this flag only if you can't make your URLs static with embeded cache busting parameter.
45 | */
46 | SDWebImageRefreshCached = 1 << 4,
47 |
48 | /**
49 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
50 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
51 | */
52 | SDWebImageContinueInBackground = 1 << 5,
53 |
54 | /**
55 | * Handles cookies stored in NSHTTPCookieStore by setting
56 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
57 | */
58 | SDWebImageHandleCookies = 1 << 6,
59 |
60 | /**
61 | * Enable to allow untrusted SSL ceriticates.
62 | * Useful for testing purposes. Use with caution in production.
63 | */
64 | SDWebImageAllowInvalidSSLCertificates = 1 << 7,
65 |
66 | /**
67 | * By default, image are loaded in the order they were queued. This flag move them to
68 | * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
69 | * could take a while).
70 | */
71 | SDWebImageHighPriority = 1 << 8,
72 |
73 | /**
74 | * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
75 | * of the placeholder image until after the image has finished loading.
76 | */
77 | SDWebImageDelayPlaceholder = 1 << 9,
78 |
79 | /**
80 | * We usually don't call transformDownloadedImage delegate method on animated images,
81 | * as most transformation code would mangle it.
82 | * Use this flag to transform them anyway.
83 | */
84 | SDWebImageTransformAnimatedImage = 1 << 10,
85 | };
86 |
87 | typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
88 |
89 | typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
90 |
91 | typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
92 |
93 |
94 | @class SDWebImageManager;
95 |
96 | @protocol SDWebImageManagerDelegate
97 |
98 | @optional
99 |
100 | /**
101 | * Controls which image should be downloaded when the image is not found in the cache.
102 | *
103 | * @param imageManager The current `SDWebImageManager`
104 | * @param imageURL The url of the image to be downloaded
105 | *
106 | * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
107 | */
108 | - (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL;
109 |
110 | /**
111 | * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
112 | * NOTE: This method is called from a global queue in order to not to block the main thread.
113 | *
114 | * @param imageManager The current `SDWebImageManager`
115 | * @param image The image to transform
116 | * @param imageURL The url of the image to transform
117 | *
118 | * @return The transformed image object.
119 | */
120 | - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL;
121 |
122 | @end
123 |
124 | /**
125 | * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes.
126 | * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache).
127 | * You can use this class directly to benefit from web image downloading with caching in another context than
128 | * a UIView.
129 | *
130 | * Here is a simple example of how to use SDWebImageManager:
131 | *
132 | * @code
133 |
134 | SDWebImageManager *manager = [SDWebImageManager sharedManager];
135 | [manager downloadWithURL:imageURL
136 | options:0
137 | progress:nil
138 | completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
139 | if (image) {
140 | // do something with image
141 | }
142 | }];
143 |
144 | * @endcode
145 | */
146 | @interface SDWebImageManager : NSObject
147 |
148 | @property (weak, nonatomic) id delegate;
149 |
150 | @property (strong, nonatomic, readonly) SDImageCache *imageCache;
151 | @property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
152 |
153 | /**
154 | * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
155 | * be used to remove dynamic part of an image URL.
156 | *
157 | * The following example sets a filter in the application delegate that will remove any query-string from the
158 | * URL before to use it as a cache key:
159 | *
160 | * @code
161 |
162 | [[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
163 | url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
164 | return [url absoluteString];
165 | }];
166 |
167 | * @endcode
168 | */
169 | @property (copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
170 |
171 | /**
172 | * Returns global SDWebImageManager instance.
173 | *
174 | * @return SDWebImageManager shared instance
175 | */
176 | + (SDWebImageManager *)sharedManager;
177 |
178 | /**
179 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
180 | *
181 | * @param url The URL to the image
182 | * @param options A mask to specify options to use for this request
183 | * @param progressBlock A block called while image is downloading
184 | * @param completedBlock A block called when operation has been completed.
185 | *
186 | * This parameter is required.
187 | *
188 | * This block has no return value and takes the requested UIImage as first parameter.
189 | * In case of error the image parameter is nil and the second parameter may contain an NSError.
190 | *
191 | * The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache
192 | * or from the memory cache or from the network.
193 | *
194 | * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
195 | * downloading. This block is thus called repetidly with a partial image. When image is fully downloaded, the
196 | * block is called a last time with the full image and the last parameter set to YES.
197 | *
198 | * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
199 | */
200 | - (id )downloadImageWithURL:(NSURL *)url
201 | options:(SDWebImageOptions)options
202 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
203 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
204 |
205 | /**
206 | * Saves image to cache for given URL
207 | *
208 | * @param image The image to cache
209 | * @param url The URL to the image
210 | *
211 | */
212 |
213 | - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
214 |
215 | /**
216 | * Cancel all current opreations
217 | */
218 | - (void)cancelAll;
219 |
220 | /**
221 | * Check one or more operations running
222 | */
223 | - (BOOL)isRunning;
224 |
225 | /**
226 | * Check if image has already been cached
227 | *
228 | * @param url image url
229 | *
230 | * @return if the image was already cached
231 | */
232 | - (BOOL)cachedImageExistsForURL:(NSURL *)url;
233 |
234 | /**
235 | * Check if image has already been cached on disk only
236 | *
237 | * @param url image url
238 | *
239 | * @return if the image was already cached (disk only)
240 | */
241 | - (BOOL)diskImageExistsForURL:(NSURL *)url;
242 |
243 | /**
244 | * Async check if image has already been cached
245 | *
246 | * @param url image url
247 | * @param completionBlock the block to be executed when the check is finished
248 | *
249 | * @note the completion block is always executed on the main queue
250 | */
251 | - (void)cachedImageExistsForURL:(NSURL *)url
252 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
253 |
254 | /**
255 | * Async check if image has already been cached on disk only
256 | *
257 | * @param url image url
258 | * @param completionBlock the block to be executed when the check is finished
259 | *
260 | * @note the completion block is always executed on the main queue
261 | */
262 | - (void)diskImageExistsForURL:(NSURL *)url
263 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
264 |
265 |
266 | /**
267 | *Return the cache key for a given URL
268 | */
269 | - (NSString *)cacheKeyForURL:(NSURL *)url;
270 |
271 | @end
272 |
273 |
274 | #pragma mark - Deprecated
275 |
276 | typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
277 | typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
278 |
279 |
280 | @interface SDWebImageManager (Deprecated)
281 |
282 | /**
283 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
284 | *
285 | * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
286 | */
287 | - (id )downloadWithURL:(NSURL *)url
288 | options:(SDWebImageOptions)options
289 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
290 | completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
291 |
292 | @end
293 |
--------------------------------------------------------------------------------
/DDRichTextLib/SDWebImage/UIButton+WebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIButton+WebCache.h"
10 | #import "objc/runtime.h"
11 | #import "UIView+WebCacheOperation.h"
12 |
13 | static char imageURLStorageKey;
14 |
15 | @implementation UIButton (WebCache)
16 |
17 | - (NSURL *)sd_currentImageURL {
18 | NSURL *url = self.imageURLStorage[@(self.state)];
19 |
20 | if (!url) {
21 | url = self.imageURLStorage[@(UIControlStateNormal)];
22 | }
23 |
24 | return url;
25 | }
26 |
27 | - (NSURL *)sd_imageURLForState:(UIControlState)state {
28 | return self.imageURLStorage[@(state)];
29 | }
30 |
31 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
32 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
33 | }
34 |
35 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
36 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
37 | }
38 |
39 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
40 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
41 | }
42 |
43 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
44 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
45 | }
46 |
47 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
48 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
49 | }
50 |
51 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
52 |
53 | [self setImage:placeholder forState:state];
54 | [self sd_cancelImageLoadForState:state];
55 |
56 | if (!url) {
57 | [self.imageURLStorage removeObjectForKey:@(state)];
58 |
59 | dispatch_main_async_safe(^{
60 | NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
61 | if (completedBlock) {
62 | completedBlock(nil, error, SDImageCacheTypeNone, url);
63 | }
64 | });
65 |
66 | return;
67 | }
68 |
69 | self.imageURLStorage[@(state)] = url;
70 |
71 | __weak UIButton *wself = self;
72 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
73 | if (!wself) return;
74 | dispatch_main_sync_safe(^{
75 | __strong UIButton *sself = wself;
76 | if (!sself) return;
77 | if (image) {
78 | [sself setImage:image forState:state];
79 | }
80 | if (completedBlock && finished) {
81 | completedBlock(image, error, cacheType, url);
82 | }
83 | });
84 | }];
85 | [self sd_setImageLoadOperation:operation forState:state];
86 | }
87 |
88 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
89 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
90 | }
91 |
92 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
93 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
94 | }
95 |
96 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
97 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
98 | }
99 |
100 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
101 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
102 | }
103 |
104 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
105 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
106 | }
107 |
108 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
109 | [self sd_cancelImageLoadForState:state];
110 |
111 | [self setBackgroundImage:placeholder forState:state];
112 |
113 | if (url) {
114 | __weak UIButton *wself = self;
115 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
116 | if (!wself) return;
117 | dispatch_main_sync_safe(^{
118 | __strong UIButton *sself = wself;
119 | if (!sself) return;
120 | if (image) {
121 | [sself setBackgroundImage:image forState:state];
122 | }
123 | if (completedBlock && finished) {
124 | completedBlock(image, error, cacheType, url);
125 | }
126 | });
127 | }];
128 | [self sd_setBackgroundImageLoadOperation:operation forState:state];
129 | } else {
130 | dispatch_main_async_safe(^{
131 | NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
132 | if (completedBlock) {
133 | completedBlock(nil, error, SDImageCacheTypeNone, url);
134 | }
135 | });
136 | }
137 | }
138 |
139 | - (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state {
140 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
141 | }
142 |
143 | - (void)sd_cancelImageLoadForState:(UIControlState)state {
144 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
145 | }
146 |
147 | - (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state {
148 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
149 | }
150 |
151 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
152 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
153 | }
154 |
155 | - (NSMutableDictionary *)imageURLStorage {
156 | NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
157 | if (!storage)
158 | {
159 | storage = [NSMutableDictionary dictionary];
160 | objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
161 | }
162 |
163 | return storage;
164 | }
165 |
166 | @end
167 |
168 |
169 | @implementation UIButton (WebCacheDeprecated)
170 |
171 | - (NSURL *)currentImageURL {
172 | return [self sd_currentImageURL];
173 | }
174 |
175 | - (NSURL *)imageURLForState:(UIControlState)state {
176 | return [self sd_imageURLForState:state];
177 | }
178 |
179 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
180 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
181 | }
182 |
183 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
184 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
185 | }
186 |
187 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
188 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
189 | }
190 |
191 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
192 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
193 | if (completedBlock) {
194 | completedBlock(image, error, cacheType);
195 | }
196 | }];
197 | }
198 |
199 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
200 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
201 | if (completedBlock) {
202 | completedBlock(image, error, cacheType);
203 | }
204 | }];
205 | }
206 |
207 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
208 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
209 | if (completedBlock) {
210 | completedBlock(image, error, cacheType);
211 | }
212 | }];
213 | }
214 |
215 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
216 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
217 | }
218 |
219 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
220 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
221 | }
222 |
223 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
224 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
225 | }
226 |
227 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
228 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
229 | if (completedBlock) {
230 | completedBlock(image, error, cacheType);
231 | }
232 | }];
233 | }
234 |
235 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
236 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
237 | if (completedBlock) {
238 | completedBlock(image, error, cacheType);
239 | }
240 | }];
241 | }
242 |
243 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
244 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
245 | if (completedBlock) {
246 | completedBlock(image, error, cacheType);
247 | }
248 | }];
249 | }
250 |
251 | - (void)cancelCurrentImageLoad {
252 | // in a backwards compatible manner, cancel for current state
253 | [self sd_cancelImageLoadForState:self.state];
254 | }
255 |
256 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state {
257 | [self sd_cancelBackgroundImageLoadForState:state];
258 | }
259 |
260 | @end
261 |
--------------------------------------------------------------------------------
/DDRichTextLib/YMTableViewCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // YMTableViewCell.m
3 | // WFCoretext
4 | //
5 | // Created by 阿虎 on 14/10/28.
6 | // Copyright (c) 2014年 tigerwf. All rights reserved.
7 | // 2 3 2 2 2 3 1 3 2 1
8 |
9 | #import "YMTableViewCell.h"
10 | #import "UIImageView+WebCache.h"
11 | #import "ContantHead.h"
12 | #import "YMTapGestureRecongnizer.h"
13 |
14 | #define kImageTag 9999
15 |
16 |
17 | @implementation YMTableViewCell
18 | {
19 | YMTextData *tempDate;
20 | }
21 |
22 | -(void)didHeadPicAndNamePress{
23 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didPromulgatorNameOrHeadPicPressedForIndex:name:")]){
24 | [self.delegate didPromulgatorNameOrHeadPicPressedForIndex:self.stamp name:self.nameLbl.text];
25 | }
26 | }
27 |
28 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
29 | {
30 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
31 | if (self) {
32 |
33 | _hideReply = NO;
34 |
35 | // Initialization code
36 | self.selectionStyle = UITableViewCellSelectionStyleNone;
37 |
38 | _headerImage = [[UIImageView alloc] initWithFrame:CGRectMake(20, 5, 50, TableHeader)];
39 | _headerImage.backgroundColor = [UIColor clearColor];
40 | _headerImage.userInteractionEnabled = YES;
41 | UIGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didHeadPicAndNamePress)];
42 | [_headerImage addGestureRecognizer:tap1];
43 | [self.contentView addSubview:_headerImage];
44 |
45 | _nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(20 + TableHeader + 20, 5, screenWidth - 120, TableHeader/2)];
46 | _nameLbl.textAlignment = NSTextAlignmentLeft;
47 | _nameLbl.font = [UIFont systemFontOfSize:15.0];
48 | _nameLbl.textColor = [UIColor colorWithRed:104/255.0 green:109/255.0 blue:248/255.0 alpha:1.0];
49 | _nameLbl.userInteractionEnabled = YES;
50 | UIGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didHeadPicAndNamePress)];
51 | [_nameLbl addGestureRecognizer:tap2];
52 | [self.contentView addSubview:_nameLbl];
53 |
54 |
55 |
56 | _introLbl = [[UILabel alloc] initWithFrame:CGRectMake(20 + TableHeader + 20, 5 + TableHeader/2 , screenWidth - 120, TableHeader/2)];
57 | _introLbl.numberOfLines = 1;
58 | _introLbl.font = [UIFont systemFontOfSize:14.0];
59 | _introLbl.textColor = [UIColor grayColor];
60 | [self.contentView addSubview:_introLbl];
61 |
62 | _imageArray = [[NSMutableArray alloc] init];
63 | _ymTextArray = [[NSMutableArray alloc] init];
64 | _ymShuoshuoArray = [[NSMutableArray alloc] init];
65 |
66 | _foldBtn = [UIButton buttonWithType:0];
67 | [_foldBtn setTitle:@"展开" forState:0];
68 | _foldBtn.backgroundColor = [UIColor clearColor];
69 | _foldBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
70 | [_foldBtn setTitleColor:[UIColor grayColor] forState:0];
71 | [_foldBtn addTarget:self action:@selector(foldText) forControlEvents:UIControlEventTouchUpInside];
72 | [self.contentView addSubview:_foldBtn];
73 |
74 | _replyImageView = [[UIImageView alloc] init];
75 |
76 | _replyImageView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
77 | [self.contentView addSubview:_replyImageView];
78 |
79 | _replyBtn = [YMButton buttonWithType:0];
80 | [_replyBtn setImage:[UIImage imageNamed:@"reply_button.png"] forState:0];
81 | [self.contentView addSubview:_replyBtn];
82 |
83 | self.backgroundColor = [UIColor whiteColor];
84 |
85 | }
86 | return self;
87 | }
88 |
89 | - (void)foldText{
90 |
91 | if (tempDate.foldOrNot == YES) {
92 | tempDate.foldOrNot = NO;
93 | [_foldBtn setTitle:@"收起" forState:0];
94 | }else{
95 | tempDate.foldOrNot = YES;
96 | [_foldBtn setTitle:@"展开" forState:0];
97 | }
98 |
99 | [_delegate changeFoldState:tempDate onCellRow:self.stamp];
100 |
101 | }
102 |
103 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
104 | [super setSelected:selected animated:animated];
105 |
106 | // Configure the view for the selected state
107 | }
108 |
109 |
110 | - (void)setYMViewWith:(YMTextData *)ymData{
111 |
112 | // NSLog(@"width = %f",screenWidth);
113 |
114 | tempDate = ymData;
115 |
116 | for ( int i = 0; i < _ymShuoshuoArray.count; i ++) {
117 | WFTextView * imageV = (WFTextView *)[_ymShuoshuoArray objectAtIndex:i];
118 | if (imageV.superview) {
119 | [imageV removeFromSuperview];
120 |
121 | }
122 | }
123 |
124 | //处理说说内容
125 | [_ymShuoshuoArray removeAllObjects];
126 | WFTextView *textView = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X, 15 + TableHeader, screenWidth - 2 * offSet_X, 0)];
127 | textView.delegate = self;
128 | textView.attributedData = ymData.attributedDataWF;
129 | textView.isFold = ymData.foldOrNot;
130 | textView.isDraw = YES;
131 | textView.type = TextTypeContent;
132 | [textView setOldString:ymData.showShuoShuo andNewString:ymData.completionShuoshuo];
133 | [self.contentView addSubview:textView];
134 |
135 | BOOL foldOrnot = ymData.foldOrNot;
136 | float hhhh = foldOrnot?ymData.shuoshuoHeight:ymData.unFoldShuoHeight;
137 |
138 | textView.frame = CGRectMake(offSet_X, 15 + TableHeader, screenWidth - 2 * offSet_X, hhhh);
139 |
140 | [_ymShuoshuoArray addObject:textView];
141 |
142 | //按钮
143 | _foldBtn.frame = CGRectMake(offSet_X - 10, 15 + TableHeader + hhhh + 10 , 50, 20 );
144 |
145 | if (ymData.islessLimit) {
146 |
147 | _foldBtn.hidden = YES;
148 | }else{
149 | _foldBtn.hidden = NO;
150 | }
151 |
152 |
153 | if (tempDate.foldOrNot == YES) {
154 |
155 | [_foldBtn setTitle:@"展开" forState:0];
156 | }else{
157 |
158 | [_foldBtn setTitle:@"收起" forState:0];
159 | }
160 |
161 |
162 | //图片部分
163 | for (int i = 0; i < [_imageArray count]; i++) {
164 |
165 | UIImageView * imageV = (UIImageView *)[_imageArray objectAtIndex:i];
166 | if (imageV.superview) {
167 | [imageV removeFromSuperview];
168 |
169 | }
170 |
171 | }
172 |
173 | [_imageArray removeAllObjects];
174 |
175 | for (int i = 0; i < [ymData.showImageArray count]; i++) {
176 |
177 | UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(((screenWidth - 240)/4)*(i%3 + 1) + 80*(i%3), TableHeader + 10 * ((i/3) + 1) + (i/3) * ShowImage_H + hhhh + kDistance + (ymData.islessLimit?0:30), 80, ShowImage_H)];
178 | image.userInteractionEnabled = YES;
179 |
180 | YMTapGestureRecongnizer *tap = [[YMTapGestureRecongnizer alloc] initWithTarget:self action:@selector(tapImageView:)];
181 | [image addGestureRecognizer:tap];
182 | tap.appendArray = ymData.showImageArray;
183 | image.backgroundColor = [UIColor clearColor];
184 | image.tag = kImageTag + i;
185 | // 这句话 让图片 支持网络异步加载图片
186 | [image sd_setImageWithURL:[NSURL URLWithString:[ymData.showImageArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"nilPic.png"]];
187 | // image.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[ymData.showImageArray objectAtIndex:i]]];
188 | [self.contentView addSubview:image];
189 | [_imageArray addObject:image];
190 |
191 | }
192 |
193 |
194 |
195 | if (_hideReply) {
196 | [_replyBtn removeFromSuperview];
197 |
198 | }else{
199 |
200 | //最下方回复部分
201 | for (int i = 0; i < [_ymTextArray count]; i++) {
202 |
203 | WFTextView * ymTextView = (WFTextView *)[_ymTextArray objectAtIndex:i];
204 | if (ymTextView.superview) {
205 | [ymTextView removeFromSuperview];
206 | // NSLog(@"here");
207 |
208 | }
209 |
210 | }
211 |
212 | [_ymTextArray removeAllObjects];
213 | float origin_Y = 10;
214 | NSUInteger scale_Y = ymData.showImageArray.count - 1;
215 | float balanceHeight = 0; //纯粹为了解决没图片高度的问题
216 | if (ymData.showImageArray.count == 0) {
217 | scale_Y = 0;
218 | balanceHeight = - ShowImage_H - kDistance ;
219 | }
220 |
221 | float backView_Y = 0;
222 | float backView_H = 0;
223 |
224 | for (int i = 0; i < ymData.replyDataSource.count; i ++ ) {
225 |
226 | WFTextView *_ilcoreText = [[WFTextView alloc] initWithFrame:CGRectMake(offSet_X,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance, screenWidth - offSet_X * 2, 0)];
227 |
228 | if (i == 0) {
229 | backView_Y = TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30);
230 | }
231 |
232 | _ilcoreText.delegate = self;
233 |
234 | _ilcoreText.type = TextTypeReply;
235 | _ilcoreText.replyIndex = i;
236 |
237 | _ilcoreText.attributedData = [ymData.attributedData objectAtIndex:i];
238 |
239 |
240 | [_ilcoreText setOldString:[ymData.replyDataSource objectAtIndex:i] andNewString:[ymData.completionReplySource objectAtIndex:i]];
241 |
242 | _ilcoreText.frame = CGRectMake(offSet_X,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance, screenWidth - offSet_X * 2, [_ilcoreText getTextHeight]);
243 | [self.contentView addSubview:_ilcoreText];
244 | origin_Y += [_ilcoreText getTextHeight] + 5 ;
245 |
246 | backView_H += _ilcoreText.frame.size.height;
247 |
248 | [_ymTextArray addObject:_ilcoreText];
249 | }
250 |
251 | backView_H += (ymData.replyDataSource.count - 1)*5;
252 |
253 |
254 |
255 | if (ymData.replyDataSource.count == 0) {//没回复的时候
256 |
257 | _replyImageView.frame = CGRectMake(offSet_X, backView_Y - 10 + balanceHeight + 5 + kReplyBtnDistance, 0, 0);
258 | _replyBtn.frame = CGRectMake(screenWidth - offSet_X - 40 + 6,TableHeader + 10 + ShowImage_H + (ShowImage_H + 10)*(scale_Y/3) + origin_Y + hhhh + kDistance + (ymData.islessLimit?0:30) + balanceHeight + kReplyBtnDistance - 24, 40, 18);
259 |
260 | }else{
261 |
262 | _replyImageView.frame = CGRectMake(offSet_X, backView_Y - 10 + balanceHeight + 5 + kReplyBtnDistance, screenWidth - offSet_X * 2, backView_H + 20 - 12);//微调
263 |
264 | _replyBtn.frame = CGRectMake(screenWidth - offSet_X - 40 + 6, _replyImageView.frame.origin.y - 24, 40, 18);
265 |
266 |
267 | }
268 |
269 |
270 | }
271 |
272 |
273 | }
274 |
275 | #pragma mark - ilcoreTextDelegate
276 | //- (void)clickMyself:(NSString *)clickString{
277 | //
278 | // //延迟调用下 可去掉 下同
279 | // dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC));
280 | // dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
281 | //
282 | // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:clickString message:nil delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
283 | // [alert show];
284 | //
285 | //
286 | // });
287 | //}
288 |
289 | - (void)clickWFCoretext:(NSString *)clickString{
290 |
291 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC));
292 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
293 |
294 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didRichTextPress:index:")]) {
295 | [self.delegate didRichTextPress:clickString index:self.stamp];
296 | }
297 | });
298 | }
299 |
300 | -(void)clickWFCoretext:(NSString *)clickString replyIndex:(NSInteger)index{
301 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC));
302 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
303 |
304 | if ([self.delegate respondsToSelector:NSSelectorFromString(@"didRichTextPress:index:replyIndex:")]) {
305 | [self.delegate didRichTextPress:clickString index:self.stamp replyIndex:index];
306 | }
307 | });
308 | }
309 |
310 | #pragma mark - 点击照片
311 | - (void)tapImageView:(YMTapGestureRecongnizer *)tapGes{
312 |
313 | [_delegate showImageViewWithImageViews:tapGes.appendArray byClickWhich:tapGes.view.tag];
314 |
315 |
316 | }
317 |
318 | -(YMTextData*)getYMTextData{
319 | return tempDate;
320 | }
321 |
322 |
323 | @end
324 |
--------------------------------------------------------------------------------