Tasks with my UIImageView - iphone

I need to do the following tasks with my UIImageView.
Highlight the UIImageView on click .
Create a clear button on right side of UIImageView.
Clear the UIImageView on the created clear button click.
Set image named as myimage.png in UIImageView which is cleared before.
Can any one help me to do it?any sample codes,apps or links to refer?

for highlighting place the imageView above a UIView,but not inside it[i.e put them both on a common super view] (with a frame 2-3 pix greater than imageView) with backgroundColor as the color of ur highlight to be .. set it hidden
create button (I hope u know how to create that) and add it to the imageView. In the button click method set that imageView.image = nil
add a tapGestureRecogniser to the imageView and in the the method set the myView.hidden = NO

If you are using IB, you can set the highlighted state of the image.
Go to the attributes inspector, its the 4th option on the right pane. Set the 'highlighted' drop down to myImage.png after copying the image into resources folder in your project.
Also, make sure the checkbox for Interaction is enabled (to user interaction enabled).
Now, add a tap gesture recognizer from the Objects menu in the bottom. Add it to the UIImageView you want. Connect the selector of the tap gesture recognizer (from the last option in the right pane or by right clicking on the tap gesture recognizer) to an IBAction to handle the tap gesture recognizer.
In that action, you can do whatever you want. Like setting a clear button etc.
You can set the imageview to highlighted using this..
self.myImageView.highlighted = YES;

Related

How to create a message box when user press on an image in swift ?

I am trying to do something like this picture.
https://i.stack.imgur.com/5JneD.png
So when a user press at a specific area in a box, a button or a message tag will appear.
Any idea where should I start from? I was able to create the box, just need when the user press a tag appears.
Add a UIImageView to your view controller. Set isUserInteractionEnabled to true for the image view. Attach a UITapGestureRecognizer to the image view.
In the handler for the tap gesture recognizer's tap handler, call location(in:) to get the coordinates of the tap in the image view's coordinate system.
Use the CGRect function contains(_:) to determine if the tap point is inside either of those areas.
Note that alternately you could simply add transparent buttons on top of your image view at the desired locations and use target/actions on those buttons to respond to the taps.

Adding UIButton to UIImageView within UIScrollView on Swift

I am writing an application for an event my organization is hosting using Swift. I have an image with the floor layout and want to add buttons to select locations (such as bathrooms, entrances, exits, emergency sections, etc) so that people can click them and information about the location pops up.
I currently have an imageview with the floor layout within a scrollview to allow the user to zoom in and out of the image. When I try to add buttons to the scrollview they don't stay relative to the image when zooming in and out, nor do their size change. I have tried adding constraints on to make the location stay the same when zooming in and out.
It also won't let me relocate the button on the storyboard to be a subview of the imageview. Looking up similar solutions says to add the button programmatically as a subview of the imageview but then it'd be really hard to put the 100+ buttons in the right location. Any suggestions as to how to go about this?
you have no other choice instead of adding by code.. because from code you can add as subview of image view , whereas Storyboard wont add buttons as subviews of imageView, but it will add buttons as subview of Scroll View

How to put my 2 existing buttons to the foreground, they are now behind an imageview

The question is in the title.
There must be a simpel way to do this I guess?
There is an imageview on the screen, there doesn't have to be any interaction with it.
On the imageview I want 2 small buttons left and right but the buttons were created (and the code is written) before the imageview. How do I set this imageview to the background? :)
[self.view sendSubviewToBack:yourImageView];
You can add buttons as subview of imageview.
you can write below code for that:
[imageView addSubview:button1];
[imageView addSubview:button2];
So buttons will be appear in foreground.
When looking at your xib or stoyboard (where you can see the layout), you can use the View Controller scene which is a list of all of the objects, views etc on your Apps layout.
You can click and drag the UI image view so its above the buttons in the list. I'm guessing it's just defaulted to being on top of the buttons.
In your storyboard, choose your viewController by clicking on it. On left side you can see hierarchy like left side view in this image. Check if your imageView is below, in hierarchy, to your 2 buttons. If it is, then drag the imageView and move it above both the buttons.
Concept : The view that is below in hierarchy is visible on top of all the views above it.

Remove UIToolBar from the View

I have a UIbutton, and when i click on that button i will show UIToolBar (located some where middle of the screen). (i coded this, and it works fine)
Now what i need to do is, when the user clicks anywhere in the screen, this toolbar should disappear. I know how to remove the uitoolbar off the screen as well toolbar.hidden = YES;
The thing i don't know is to remove the uitoolbar when the user clicks anywhere in the screen.
How can i code this ?
Create a full screen view (to be used as container, set its backgroundColor to clearColor), add to this container view another full screen view (which can have a black background color and alpha 0.6) and then add your toolbar to the container view. In that second full screen view add a tapGestureRecognizer and in its selector, perform your animations, where you can do a cool fadeout. Use the completion block of the animation to remove/release anything you have to.
Try setting nil for your UIToolbar. that is set the object value to nil for your toolbar.

how to create a IB action for a image view

i have a image ,i want to launch url when i press that logo or image ,how to implement ib action for that image view ...
can any one give suggestion i selected image view in ib to place my logo is it right?
UIImageView is not a subclass of UIControl so it doesn't support the target-action mechanism. You have 2 options:
Use a UIButton instead (and set your image as the button's background image).
Set userInteractionEnabled = YES; on your image view and implement the touch handling in -touchesMoved:` etc. yourself.