Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When adding a photo - it should be resized to fit frame ( and handle orientation changes ) #28

Open
ZoeESummers opened this issue Nov 3, 2013 · 1 comment

Comments

@ZoeESummers
Copy link

List_Implementation Branch

When adding a photo - it should be resized to fit frame ( and handle orientation changes )

Eitehr that, or a small placeholder should be pasted in, and upon touching a modal full size one is show (again, working in both orientations.)

@ZoeESummers
Copy link
Author

This isn't FULLY working - it's working for Landscape, but not Portrait properly - and doesn't dynamically adjust previously saved photos..

But this is changes to your RichTextEditor.m

  • ( void ) richTextEditorToolbarDidSelectTextAttachment:( UIImage * )textAttachment
    {
    UIViewController * parentView = nil;
    CGFloat textWindowWidth = 0.0f;

    if ( self.delegate != nil )
    {
    parentView = (UIViewController * )self.delegate;
    }

    if ( UIInterfaceOrientationIsPortrait( parentView.interfaceOrientation ) )
    {
    textWindowWidth = self.frame.size.height;
    }
    else if ( UIInterfaceOrientationIsLandscape( parentView.interfaceOrientation ) )
    {
    textWindowWidth = self.frame.size.width;
    }

    CGSize currentSize = textAttachment.size;

    CGFloat biggestDimension = 0.0f;

    if ( currentSize.width > currentSize.height )
    {
    biggestDimension = currentSize.width;
    }
    else
    {
    biggestDimension = currentSize.height;
    }

    CGFloat resizeRatio = 0.0f;

    if ( biggestDimension > textWindowWidth )
    {
    resizeRatio = textWindowWidth / biggestDimension;
    }
    else
    {
    resizeRatio = 1.0f;
    }

    CGSize newSize = CGSizeMake( currentSize.width * resizeRatio, currentSize.height * resizeRatio );

    textAttachment = [self imageWithImage:textAttachment scaledToSize:newSize];

    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
    [attachment setImage:textAttachment];
    NSAttributedString *attributedStringAttachment = [NSAttributedString attributedStringWithAttachment:attachment];

    NSMutableAttributedString *attributedString = [self.attributedText mutableCopy];
    [attributedString insertAttributedString:attributedStringAttachment atIndex:self.selectedRange.location];
    self.attributedText = attributedString;
    }

  • ( UIImage * ) imageWithImage:( UIImage * )image scaledToSize:( CGSize )newSize
    {
    UIGraphicsBeginImageContextWithOptions( newSize, NO, 0.0f );

    [image drawInRect:CGRectMake( 0.0f, 0.0f, newSize.width, newSize.height )];

    UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant