4

I am completely stumped on this problem and it should be so simple that its driving me nuts.

I am working with this apple reflection tutorial.

Apple Reflection Example

They have the image gradient that shows up from top to bottom.

  • How can I make a gradient from left to right
  • how can I flip the image horizontally. In their example they flip the image vertically.

any help?

//The gradient code is here but I don't know what should be the gradient start / end points
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
.....
gradientStartPoint = CGPointZero;
        gradientEndPoint = CGPointMake(0, pixelsHigh);
}

//similarly I know the image flip happens here but for life of me I cannot make it flip horizontally

- (UIImage *)reflectedImage:(UIImageView *)fromImage withHeight:(NSUInteger)height
{
.....
CGContextTranslateCTM(mainViewContentContext, 0.0, height);
        CGContextScaleCTM(mainViewContentContext, 1.0, -1.0);
}
0

1 Answer 1

4

Try this:

//horizontal gradient
CGImageRef CreateGradientImage(int pixelsWide, int pixelsHigh)
{
    .....
    gradientStartPoint = CGPointZero;
    gradientEndPoint = CGPointMake(pixelsWide, 0);
}

//horizontal flip

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
    .....
    CGContextTranslateCTM(mainViewContentContext, width, 0,0);
    CGContextScaleCTM(mainViewContentContext, -1.0, 1.0);
}

For the horizontal flip you should add a new method, since you have to specify the width, no the height.

Good Luck!

EDIT 1:

In order to get the gradient, you should add another modification to reflectedImage:withWidth.

- (UIImage *)reflectedImage:(UIImageView *)fromImage withWidth:(NSUInteger)width
{
    .....
    CGImageRef gradientMaskImage = CreateGradientImage(width, 1);
    .....
}
3
  • thanks for the code. The horizontal flip works perfectly but the left to right gradient doesn't work right. It shows the gradient all over the image instead of starting somewhere in the middle and going all the way right
    – Sam B
    Jan 16, 2013 at 3:53
  • I attached an image in my post of what I see when I enter this for gradient gradientStartPoint = CGPointZero; gradientEndPoint = CGPointMake(pixelsWide, 0);
    – Sam B
    Jan 16, 2013 at 3:59
  • Hi Luis, I have one more follow up question - if you could help with that too then that would be great - stackoverflow.com/questions/14361660/…
    – Sam B
    Jan 16, 2013 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.