Obviously, I skipped UIImageView versus UIImage to register a gesture (e.g. click / click) on the image, I need to have the image in uiimageview and the registration gesture on uiimageview, not uiimage.
So this piece of code works for me:
- (void)drawRect:(CGRect)rect { Obj *obj = ... obj has imageHref which is NSString UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:obj.imageHref]]; [image drawInRect:CGRectMake((self.frame.size.width/2) - (image.size.with/2), (self.frame.size.height / 2) - (image.size.height / 2), image.size.width, image.size.height)]; }
This gives me a centered image, but it's useless because I want it to be clickable, so although I just do it with UIImageview, and not like this:
- (void)drawRect:(CGRect)rect { Obj *obj = ... obj has imageHref which is NSString UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:obj.imageHref]]; CGRect rect1=CGRectMake((self.frame.size.width/2) - (image.size.width/2), (self.frame.size.height / 2) - (image.size.height / 2), image.size.width, image.size.height); UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:radioStationImage]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)]; [backgroundImageView addGestureRecognizer:tap]; [backgroundImageView drawRect:rect1]; }
I just want to make this image clickable to do some action when clicked, how difficult is it?
EDIT:
I really implement:
https://github.com/andreyvit/SoloComponents-iOS/tree/master/ATPagingView
Which offers a neat scroll page. But with clickable images in the middle of the screen is not page 1, 2, etc.
EDIT 2:
Any perspective today?
source share