Populate API data on action button shows in Image - iphone

I am working on App in which images comes from the server. Now in that image some of the points will be already there on which on i have to make a click action & show information of that particular touch.
Here is sample Image:
Now here in above image you can see the points. that is a part of image. I need to put action over there if click on that area than show the information of that particular area from API.
Can anyone suggest me the way of it & also any alternative solution if this one is not possible.
Thanks.

Assuming that your API also tells you a co-ordinate for those points that are highlighted in the image, then...
Calculate a CGRect based on the point, either as a fixed size if they are all the same, or based on the text the API would have to supply you.
Add a UIButton as a subview to the view holding the UIImageView, make this button a CustomType, with no text or background image.
Add a tag to the UIButton so that you can uniquely identify an clicks
Add targets for the buttons, in the IBAction, use the tag from the UIButton to work out the element you are interested in and process accordingly.
If you're API isn't given you positions of the points, then I would suggest the API needs improving

Related

Create a UIScrollView that can be embedded into another view

I'm trying to build a custom, reusable UIScrollView that can be added to multiple views. The scroll view is going to be a weight picker. For the life of me, I can't find a decent example for how to implement this neatly or cleanly.
I would love for someone to point me to an existing library or tutorial that shows me how to do this. I've hacked apart a few examples, but so far, nothing is very good or reusable. Please help!!
For what it's worth, I have an image that individual ticks for the weight. So I can select to the tenth of the number (e.g. 160.4). The image has the first tick bold and larger than the remaining 9. I'd like to have the weight/number centered over the large tick. I'll update the points to my label/datasource after scrolling stops.
UPDATE
I need to make this. I have the custom font, background, and ticker image.
I would not do this through an UIScrollView. I think it would be more complex and you would certainly end up having issues when trying to add you custom picker into another scroll view.
What I would do is:
building the picker view by means of a series of CALayers, each one representing a "building block" of your picker view; see attached image:
each building block would represent a specific value by mixing a UILabel (the text) and an image;
use a pan gesture recognizer, or alternatively define touchesBegin/Moved/Ended method to deal with panning;
when a pan is done, you displace the view content to the left or right according to the panning;
when panning, you also add new building blocks to the left or right end of the picker to account for empty areas that would be revealed by the displacement done at point 4.
I think that having a look at another kind of custom control source code would be of great help to you. You would not possibly find your custom picker already implemented, but could get some guidance. Have a look then at cocoa controls.
Hope this helps.
If I were going to implement this, I would create a really wide image that had every weight on it I'd ever need - I would probably create this in code when the app started up. This image is then used as the contentView of your picker. You get all the scrolling features "for free", and you could even update the values shown in the other parts of the view during scrolling (or dragging.
The scrollView is just the area with the tick marks and weight numbers, and resides in a subview above the background, but below the centered vertical line that shows the actual weight.
EDIT: on second thought, forget the image. If you have the code to draw the image, you can do the drawing in a custom UIView. So you get the draw rect, you know the contentOffset, so you can draw just what you need.

Make fix size round button as image in iphone sdk

I am developing an application in which I need to round button as image (as I uploaded).
It Show two corner are straight and the rest is in round shape. I tried withmybutton.layer.cornerRadius but make round whole image. I also tried to just make custom button but it leave extra space in button around image i need to fix size button as image show.
Please help me. Thanks in advance. Happy Day.
Here is a one good tutorial on this:
http://iphonedevelopment.blogspot.in/2010/03/irregularly-shaped-uibuttons.html
you can download code from here
https://github.com/ole/OBShapedButton
Hope this helps
An alternate but not really a good one first add an imageView add this particular image over it than add an custom invisible button over the image by adjusting size of the button it will not cover the whole image though but still it will work fine...actually i did use this approach in one of my app :p
OBShapedButton might help. It's an open source UIButton subclass optimized for non-rectangular button shapes. If it still doesn't work, making your own buttons isn't that difficult either. Use a UIView and handle touches within the view. For eg, in touchesMoved:, set the active image and in touchesEnded:, handle the click event!

Detect blank areas in an image

I Have an image in which there are some blank areas.What i want is that when the user touches these blank areas a pop up should come asking the user to select an image that can be added to that area.I have done this by just adding a button in the background of the blank area.That worked for a few images.Since the position of the blank area varies for each image that is not a good idea to follow.So is there any provision in ios to detect blank areas and thus make them act like a button. In the image you can see the text "Place your image here".
I want that area to work somewhat like a button.any help
You will need to have some metadata associated with each image. The data will tell you where to put each button. I doubt you can find some code to automatically detect where to put the buttons.

UIImageView interactions

I am working on an app in which I want similar kind of functionality as that of WebMD body image.
How can I identify which part of image is touched in an optimal way? Do I have to slice the image according to requirements?
How can I add some tags into the image? Similar to the facebook photo upload functionality in iphone.
You need some way to figure out what the user touched, or tried to touch.
You might use a list of annotation-like objects, where each object has a location. When the user touches the image, you'll need to find the annotation in the list that's closest to the touch location and react appropriately. The "optimal" way to do that is probably to use a quad tree. For an iPhone app, though, the number of touchable points is probably pretty small (several dozen?), and a brute force search through the list will probably be more than fast enough.
Another option would be to overlay a transparent view on top of your image for each region that you want the user to be able to touch. Doing this would also make it simple to draw a "tag" at each of those locations.

UI Button with Image Smaller than Touchable Area

I've not much response so am adding some more info.
My buttons are not rectangular, nor organised in a grid so I need a way of creating what looks like a button (and shows that it has been pressed visually, as per a standard UIButton) but where the touchable area is different to the image area.
I am using a transparent PNG and that element works fine. I've added the buttons in Interface Builder and am wondering if that is the problem.
However, if I change imageEdgeInsets, it distorts the image display, which is obviously not what I want.
Bizarrely, if I increase the dimemsions of the button, it doesn't change the image, but if I decrease them it does.
I have tried different combinations of mode (scale to fill etc), but to no avail.
I am aware that there is an image and background image property, but in IB there is only one.
Essentially, I don't understand how the geometry works and the Apple documentation doesn't seem to help.
Surely, I can't be the only person to try to do this. Any help would be warmly welcomed.
Many thanks,
Chris.
Try setting the buttons setting to Aspect Fit. This will fill the button with your image so a smaller image than the button size would leave the space around the image.
Also set the button type to custom.
In the end, I stumbled across Ole Begemann's Non-rectangular buttons class. It just does what I need - to be able to create buttons where the touchable area follows the visible element of a non rectangular image.
#Helium3 - thanks - that allowed me to use a larger touch area, bit not a smaller one.