Мне нравится использовать:
myString = Regex.Replace(myString, @"\s+", " ");
, Так как это поймает выполнения любого вида пробела (например, вкладки, новые строки, и т.д.) и заменит их одиночным пробелом.
CTM влияет на будущие чертежи; вы фиксируете то, что уже нарисовали. Вам нужно объединить это преобразование до рисования, а не после.
Вот код, который я написал на основе этого ответа, на случай, если это поможет кто угодно:
#import <QuartzCore/QuartzCore.h>
...
+ (UIImage *) flipImageVertically:(UIImage *)originalImage {
UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(tempImageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform flipVertical = CGAffineTransformMake(
1, 0, 0, -1, 0, tempImageView.frame.size.height
);
CGContextConcatCTM(context, flipVertical);
[tempImageView.layer renderInContext:context];
UIImage *flipedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[tempImageView release];
return flipedImage;
}