Support for 100% width on images #350

Open
holgersindbaek opened this Issue Mar 17, 2013 · 5 comments

Projects

None yet

5 participants

@holgersindbaek

This is a feature request, so feel free to ignore.

I have an image in my html and I would like that image to be 100% of the ContentView it's in. Right now I'm accomplishing this by replacing the placeholder with the actual width each time I draw:

htmlString = [htmlString stringByReplacingOccurrencesOfString:@"**ArticleImageWidthPlaceholder**" withString:[NSString stringWithFormat:@"%i", self.screenWidth]];

Would love to be able to just write:

img{
    width: 100%;
    display: block;
}

Let me know what you think.

@holgersindbaek

@Cocoanetics Do you think this one would be a hard one to implement?

@odrobnik
Collaborator

Yes, not easy.

The problem there is that there is only a minimal implementation of the HTML box model. Issues #343 and #293 are also related to this. The box model so far are text boxes added in an array of the attributed string. This is used for setting padding and margins.

DTTextAttachments presently have no concept of where they are located in, they just know how to respond with their required size information to the run delegate.

I'm thinking that somehow the text attachment should be able to ask the content view for available width when sizing. Currently the max image size is being passed via options to textAttachmentWithElement:options: and that statically shrinks the display size of the attachment if it exceeds it.

I see two possible ways forward:

  1. Change this behavior such that DTTextAttachment gets a sizing delegate method and inquires the sizing delegate for available space whenever it is needed. This would replace the static sizing with a dynamically provided maximum size.
  2. dispense with the maximum size altogether at the image level and move that into the boxing model. The boxes would then have some sort of communication where one box could ask its parent and the root box would ask the content view. An text attachment would then be some special kind of box in this hierarchy.

I am unsure which of these would be better.

The basic workaround is to manually adjust the attachment's display size before triggering a re-layout.

@ericbeekman

@Cocoanetics I have got a DTAttributedTextContentView in a tableviewcell with images, but I'm having trouble achieving 100% width images using Autolayout.

In this delegate method, I fetch the remote image

- (UIView *)attributedTextContentView:(DTAttributedTextContentView *)attributedTextContentView viewForAttachment:(DTTextAttachment *)attachment frame:(CGRect)frame

through AFNetworking. When I get it I resize it to the max width

    for (DTTextAttachment *oneAttachment in [_text.layoutFrame textAttachments]) {
        oneAttachment.originalSize = size;
        size = [self aspectResize:size];
        if (!CGSizeEqualToSize(size, oneAttachment.displaySize)) {
            oneAttachment.displaySize = size;
        }
    }

The width becomes 100%, but the total height doesn't account for when I relayout.

CGSize expectedLabelSize = [_text suggestedFrameSizeToFitEntireStringConstraintedToWidth:_text.frame.size.width];

Do you have any idea how to fix the height? Apparently it doesn't take the resized images into account in the suggestedFrameSizeToFitEntireStringConstraintedToWidth: method.

@jwilliams-handy

@Cocoanetics this issue specifies 100% but I just wanted to clarify if this applies to any percentage style layout because I'm seeing irregardless of the value? Seems that's the expected behavior given the explanation. Are there any plans to work on this given the proposed solutions?

@KKKiller

so tht issue was still not solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment