Oddly shaped buttons - swift

How can I set an image as a button but have the boundaries of the image be the boundaries of the button as well? i.e. a trapezoid that appears on the users screen but the user can only click within the trapezoid.
I know this exists in Objective C as OBShapedButton but I would like to do the same using swift.
Thanks so much

Related

Dynamicly resizeable custom Buttons - how to make?

please I have bought GUI pack for 2D mobile games. I have vectors for buttons but I don't know how to make it "smaller" - dynamically resizable for Unity.
This is my bought button:
And I need to make from it this (with all corners, etc.)
In Unity, I will resize it according to my needs and add text. But I don't know how to make it in Photoshop or Illustrator, how to smaller it with keep corners and make "middle" of button to be dynamic.
I think that you can use the "Image Type" property on your Sprite component.
http://docs.unity3d.com/Manual/script-Image.html
That option gives you the possibility of scaling the center of the image, keeping the size of the borders.
In this video they explain the property (from 1:16 aprox)
https://www.youtube.com/watch?v=WFQcc1GUe7U
Cheers !

Populate API data on action button shows in Image

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

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.

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.

UIButton: Need a circle hit area

Ok I have 6 custom UIButtons. Their normal state image are all circles images.
They are all spaced out equally but all the circles touch each other.
The problem with the custom UIbutton (which has a circle image on it), is that the hit area of that button is square, and the corners of this square overlaps the hitarea of the other custom button's hitarea.
How do i make the hit area of a UIbutton whos normal state has a circle image, be only clickable on that circle only, rather than the normal square hit area?!
I hope that someone can find a way for me to solve this problem that i currently am having!
Thanks in advance
Pavan
If the square area of a "circle" is clicked on, you should then check if the distance between the center of the circle and the coordinates of the click are less than the radius of the circle. If not, then the "hit" can be ignored.
Thanks for the input demi, I just basically put hidden buttons on top of the images. They weren't really circles, they were more complex shapes; hence the reason I didn't bother about the maths, so I just placed hidden buttons on top of the images themselves and make those hit areas and cover appropriately until I get the desired hit area coverage I need.
Although not very neat, it works well! :D
Thanks once again for the swift reply demi.
OBShapedButton is an awesome project that will give you a button that will only respond to taps that are in the images area. I've messed with a few projects that say they do the same thing, and this one is the best I've seen so far.