Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way to add a reflection to a UIImageView

I just want the easiest way to make a reflection under a UIImageVies that is easily managable.

like image 308
Jab Avatar asked Jan 13 '10 17:01

Jab


People also ask

How do I add actions to UIImageView?

Open the Library, look for "Tap Gesture Recognizer" object. Drag the object to your storyboard, and set the delegate to the image you want to trigger actions.

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

What is use of UIImageView?

An image object may contain a single image or a sequence of images for use in an animation. You can use image objects in several different ways: Assign an image to a UIImageView object to display the image in your interface. Use an image to customize system controls such as buttons, sliders, and segmented controls.


2 Answers

Just use the sample code in the the iPhone SDK library

Update: Link now updated to new location

like image 75
JBRWilkinson Avatar answered Oct 12 '22 23:10

JBRWilkinson


As Phil says, you can have a "reflected" UIImageView instance:

@interface ReflectedImageView : UIView 
{
@private
    UIImageView *_imageView;
    UIImageView *_imageReflectionView;
}

@property (nonatomic, retain) UIImage *image;

@end

And then, in your implementation, something like this

@implementation ReflectedImageView

@dynamic image;

- (id)initWithFrame:(CGRect)frame 
{
    if (self = [super initWithFrame:frame]) 
    {
        self.backgroundColor = [UIColor clearColor];

        // This should be the size of your image:
        CGRect rect = CGRectMake(0.0, 0.0, 320.0, 290.0);

        _imageReflectionView = [[UIImageView alloc] initWithFrame:rect];
        _imageReflectionView.contentMode = UIViewContentModeScaleAspectFit;
        _imageReflectionView.alpha = 0.4;
        _imageReflectionView.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 290.0);
        [self addSubview:_imageReflectionView];

        _imageView = [[UIImageView alloc] initWithFrame:rect];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return self;
}

- (void)setImage:(UIImage *)newImage
{
    _imageView.image = newImage;
    _imageReflectionView.image = newImage;
}

- (UIImage *)image
{
    return _imageView.image;
}

- (void)dealloc 
{
    [_imageView release];
    [_imageReflectionView release];
    [super dealloc];
}

@end
like image 45
Adrian Kosmaczewski Avatar answered Oct 13 '22 00:10

Adrian Kosmaczewski