LiveUI / FTCoreText

An open source Objective-C interface component that makes use of the CoreText framework to render static text content using a highly customisable markup syntax.
MIT License
781 stars 125 forks source link

(request) : be able to load remote images #12

Open y0hnn opened 12 years ago

y0hnn commented 12 years ago

Hi, It would be awesome if we can load images remotely :) ! I tried to but it did not work. Maybe you can edit my code to implement it easier in the repo ? look at this : stackoverflow.com/questions/11927942/ios-core-text-loosing-context-when-drawing-image-inside-a-block

dourgulf commented 12 years ago

I have do some modify to support dynamic loading remote images, but it add a depend on SDWebImage(maybe rewrite the loading progress), add it to the processText method else if (currentSupernode.isImage) { //replace active string with emptySpace NSRange elementContentRange = NSMakeRange(currentSupernode.startLocation, tagRange.location - currentSupernode.startLocation); NSString * elementContent = [processedString substringWithRange:elementContentRange];

                UIImage *img = nil;
                if ([elementContent hasPrefix:@"http"]) {
                    // image from http
                    // try to load from cache
                    img = [[SDImageCache sharedImageCache] imageFromKey:elementContent];
                    if (!img) {
                        // not in cache, load it from URL
                        img = [UIImage imageNamed:@"loading"];
                        NSURL *imgURL = [NSURL URLWithString:elementContent];
                        NSLog(@"loading image %@", elementContent);
                        // download it
                        id successblock = ^(UIImage *image) {
                            NSLog(@"loaded %@", elementContent);
                            currentSupernode.image = image;
                            currentSupernode.style.leading = image.size.height;
                            [self didMakeChanges];
                            if ([self superview]) [self setNeedsDisplay];
                        };
                        id failedblock = ^(NSError *error) {
                            NSLog(@"load image failed %@", elementContent);
                        };
                        [[SDWebImageManager sharedManager] downloadWithURL:imgURL
                                                                  delegate:self
                                                                   options:0
                                                                   success:successblock
                                                                   failure:failedblock];
                    }
                }
                else
                {
                    img = [UIImage imageNamed:elementContent];
                }
                if (img) {
                    currentSupernode.image = img;
                }
                else {
                    NSLog(@"FTCoreTextView :%@ - Couldn't find image '%@' in main bundle", self, NSStringFromRange(elementContentRange));
                    [processedString replaceCharactersInRange:tagRange withString:@""];
                }
ghost commented 12 years ago

I modified with your code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

can i remove original "else if (currentSupernode.isImage){ ....} or not?

cescofry commented 12 years ago

There are specifics tags to refer to for special instances like images and unordered lists. They are listed in the header file. Fra.

Francesco Frison Cescofry@gmail.com +447766561587 From my iPhone

On 2 Sep 2012, at 13:41, KommyKT notifications@github.com wrote:

I modified with yout code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

— Reply to this email directly or view it on GitHubhttps://github.com/FuerteInternational/FTCoreText/issues/12#issuecomment-8221559.

dourgulf commented 12 years ago

the image property is UIImage * type which add to FTCoreTextNode class. (BTW, I have do much modification for this project, but I don't how to push my work.)

2012/9/2 KommyKT notifications@github.com

I modified with yout code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

— Reply to this email directly or view it on GitHubhttps://github.com/FuerteInternational/FTCoreText/issues/12#issuecomment-8221559.

ghost commented 12 years ago

Yout can send the modified code by e-mail or any filesharing portal.

On Sep 19, 2012, at 8:19 AM, dourgulf notifications@github.com wrote:

the image property is UIImage * type which add to FTCoreTextNode class. (BTW, I have do much modification for this project, but I don't how to push my work.)

2012/9/2 KommyKT notifications@github.com

I modified with yout code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

— Reply to this email directly or view it on GitHubhttps://github.com/FuerteInternational/FTCoreText/issues/12#issuecomment-8221559.

— Reply to this email directly or view it on GitHub.

cescofry commented 12 years ago

Or you can do a push request on github. Francesco.

Francesco Frison Mobile: +447766561587 [UK] Mail: cescofry@gmail.com Skype: ziofritz --- www.ziofritz.com ---

On 19 Sep 2012, at 11:18, KommyKT notifications@github.com wrote:

Yout can send the modified code by e-mail or any filesharing portal.

On Sep 19, 2012, at 8:19 AM, dourgulf notifications@github.com wrote:

the image property is UIImage * type which add to FTCoreTextNode class. (BTW, I have do much modification for this project, but I don't how to push my work.)

2012/9/2 KommyKT notifications@github.com

I modified with yout code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

— Reply to this email directly or view it on GitHubhttps://github.com/FuerteInternational/FTCoreText/issues/12#issuecomment-8221559.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

dourgulf commented 12 years ago

I have open a new repository on github. Hope it will help you.

On 2012-9-19, at 下午6:18, KommyKT notifications@github.com wrote:

Yout can send the modified code by e-mail or any filesharing portal.

On Sep 19, 2012, at 8:19 AM, dourgulf notifications@github.com wrote:

the image property is UIImage * type which add to FTCoreTextNode class. (BTW, I have do much modification for this project, but I don't how to push my work.)

2012/9/2 KommyKT notifications@github.com

I modified with yout code, but get an error, for this line: currentSupernode.image = image; and currentSupernode.image = img; the error: Property 'image' not found on object of type 'FTCoreTextNode *'

— Reply to this email directly or view it on GitHubhttps://github.com/FuerteInternational/FTCoreText/issues/12#issuecomment-8221559.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub.

PKPranav commented 10 years ago

plz upadate it