Question

I have a scrollView and inside this scrollView, there are various PFImageView objects.

I need a single UIButton object on every PFImageView (same place and same button) that will load a subView with the information of the image tapped.

Is this possible?

Was it helpful?

Solution 2

You can't have a single control in multiple locations, it's that simple. I saw your comment about not wanting to use a UICollectionView because it's not the design you're looking for, but I wonder what kind of design you want to create with UIScrollView only because UICollectionView doesn't works.

UICollectionView is not restrained to line/grid display of cells, but can be customized in a huge amounts of ways. You should watch the WWDC 2012 video "Introducing Collection Views" : at the end of it, some UICollectionView possibilities are shown and some of them are quite impressive.

Also, https://www.cocoacontrols.com/ website is a good place to find custom controls and even inspiration for your own design.

This is a little digression from the original issue, but I really think that a collection of UIImageView within an UIScrollView can be created with a UICollectionView, especially if you want to add some controls within your "cells".

OTHER TIPS

So, let me get this straight... You want to create only one button, place it on multiple imageViews and have it respond differently (depending on which imageView was tapped)?

In this case...
No, you can't have 1 button in N places.

But... you can create N button objects and have them all assigned to 1 single target method in which... you can have different functionality based on the button's tag.

PS: UICollectionView would be cleaner approach.

Yes. You should use specific control events when adding actions to the button.

E.g. in my application i record/stop/cancel sound as long as user hold a button (drag out to cancel).. like a walkie talkie phone...

[recordButton addTarget:self action:@selector(recordStart) forControlEvents:UIControlEventTouchDown];
[recordButton addTarget:self action:@selector(recordStop) forControlEvents:UIControlEventTouchUpInside];
[recordButton addTarget:self action:@selector(recordCancel) forControlEvents:UIControlEventTouchDragExit];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top