Open ZoeESummers opened 11 years ago
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; }
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.)