How to create imageView click event in iOS?
up vote
0
down vote
favorite
Note:
ImageView Click event is available in Android, I Want to know whether it's available or not in iOS
I am new to iOS, please consider, I have camera image, OnClick of it I have to open my device camera, but I am getting function of Action for image. Attaching screenshot

My code:
import UIKit
class AttendanceViewController: UIViewController {
@IBOutlet weak var loginimagebtn: UIImageView!
@IBOutlet weak var loginstatus: UITextView!
@IBOutlet weak var displayloginimg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
func openCamer() {
if UIImagePickerController.isSourceTypeAvailable(
UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker,animated: true,completion : nil)
}
}
// For Toast message below code
func showToast(message : String) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.textAlignment = .center;
toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10;
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
})
}
}
ios swift uiimageview
|
show 10 more comments
up vote
0
down vote
favorite
Note:
ImageView Click event is available in Android, I Want to know whether it's available or not in iOS
I am new to iOS, please consider, I have camera image, OnClick of it I have to open my device camera, but I am getting function of Action for image. Attaching screenshot

My code:
import UIKit
class AttendanceViewController: UIViewController {
@IBOutlet weak var loginimagebtn: UIImageView!
@IBOutlet weak var loginstatus: UITextView!
@IBOutlet weak var displayloginimg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
func openCamer() {
if UIImagePickerController.isSourceTypeAvailable(
UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker,animated: true,completion : nil)
}
}
// For Toast message below code
func showToast(message : String) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.textAlignment = .center;
toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10;
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
})
}
}
ios swift uiimageview
1
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
1
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19
|
show 10 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Note:
ImageView Click event is available in Android, I Want to know whether it's available or not in iOS
I am new to iOS, please consider, I have camera image, OnClick of it I have to open my device camera, but I am getting function of Action for image. Attaching screenshot

My code:
import UIKit
class AttendanceViewController: UIViewController {
@IBOutlet weak var loginimagebtn: UIImageView!
@IBOutlet weak var loginstatus: UITextView!
@IBOutlet weak var displayloginimg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
func openCamer() {
if UIImagePickerController.isSourceTypeAvailable(
UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker,animated: true,completion : nil)
}
}
// For Toast message below code
func showToast(message : String) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.textAlignment = .center;
toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10;
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
})
}
}
ios swift uiimageview
Note:
ImageView Click event is available in Android, I Want to know whether it's available or not in iOS
I am new to iOS, please consider, I have camera image, OnClick of it I have to open my device camera, but I am getting function of Action for image. Attaching screenshot

My code:
import UIKit
class AttendanceViewController: UIViewController {
@IBOutlet weak var loginimagebtn: UIImageView!
@IBOutlet weak var loginstatus: UITextView!
@IBOutlet weak var displayloginimg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
func openCamer() {
if UIImagePickerController.isSourceTypeAvailable(
UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker,animated: true,completion : nil)
}
}
// For Toast message below code
func showToast(message : String) {
let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-100, width: 150, height: 35))
toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
toastLabel.textColor = UIColor.white
toastLabel.textAlignment = .center;
toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = 10;
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
})
}
}
ios swift uiimageview
ios swift uiimageview
edited Nov 19 at 11:03
asked Nov 19 at 8:47
Gowthaman M
4,24051337
4,24051337
1
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
1
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19
|
show 10 more comments
1
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
1
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19
1
1
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
1
1
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19
|
show 10 more comments
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
okay do the following step
Step -1
drag and drop UIbutton to the current viewcontroller
Step -2
delete the default title for your button

step-3
UIbutton has property Image --> go to image add your camera Image like follow and finally change the button frame based on your need

Step - 4
go to connection Inspector --> select your camera button event of Touch Up Inside and create the event for your button , for e.g

option - 2
if you want to proceed with your imageview I mean you dont want to proceed with UIButton then follow this code
let cameraTap = UITapGestureRecognizer(target: self, action: #selector(cameraTapped))
displayloginimg.isUserInteractionEnabled = true
displayloginimg.addGestureRecognizer(cameraTap)
and handle the event for your imageview
@objc func cameraTapped() {
// open your camera controller here
}
add a comment |
up vote
6
down vote
You can achieve this functionality on UIImageView using UITapGestureRecognizer.
Use below code in your viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
let tapGetsure = UITapGestureRecognizer(target: self,
action: #selector(self.openCamer))
tapGetsure.numberOfTapsRequired = 1
loginimagebtn.gestureRecognizers = tapGetsure
loginimagebtn.isUserInteractionEnabled = true
}
Hi sir...can you tell me how to open front camera by default and please check myopenCamer()function
– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
|
show 1 more comment
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
okay do the following step
Step -1
drag and drop UIbutton to the current viewcontroller
Step -2
delete the default title for your button

step-3
UIbutton has property Image --> go to image add your camera Image like follow and finally change the button frame based on your need

Step - 4
go to connection Inspector --> select your camera button event of Touch Up Inside and create the event for your button , for e.g

option - 2
if you want to proceed with your imageview I mean you dont want to proceed with UIButton then follow this code
let cameraTap = UITapGestureRecognizer(target: self, action: #selector(cameraTapped))
displayloginimg.isUserInteractionEnabled = true
displayloginimg.addGestureRecognizer(cameraTap)
and handle the event for your imageview
@objc func cameraTapped() {
// open your camera controller here
}
add a comment |
up vote
5
down vote
accepted
okay do the following step
Step -1
drag and drop UIbutton to the current viewcontroller
Step -2
delete the default title for your button

step-3
UIbutton has property Image --> go to image add your camera Image like follow and finally change the button frame based on your need

Step - 4
go to connection Inspector --> select your camera button event of Touch Up Inside and create the event for your button , for e.g

option - 2
if you want to proceed with your imageview I mean you dont want to proceed with UIButton then follow this code
let cameraTap = UITapGestureRecognizer(target: self, action: #selector(cameraTapped))
displayloginimg.isUserInteractionEnabled = true
displayloginimg.addGestureRecognizer(cameraTap)
and handle the event for your imageview
@objc func cameraTapped() {
// open your camera controller here
}
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
okay do the following step
Step -1
drag and drop UIbutton to the current viewcontroller
Step -2
delete the default title for your button

step-3
UIbutton has property Image --> go to image add your camera Image like follow and finally change the button frame based on your need

Step - 4
go to connection Inspector --> select your camera button event of Touch Up Inside and create the event for your button , for e.g

option - 2
if you want to proceed with your imageview I mean you dont want to proceed with UIButton then follow this code
let cameraTap = UITapGestureRecognizer(target: self, action: #selector(cameraTapped))
displayloginimg.isUserInteractionEnabled = true
displayloginimg.addGestureRecognizer(cameraTap)
and handle the event for your imageview
@objc func cameraTapped() {
// open your camera controller here
}
okay do the following step
Step -1
drag and drop UIbutton to the current viewcontroller
Step -2
delete the default title for your button

step-3
UIbutton has property Image --> go to image add your camera Image like follow and finally change the button frame based on your need

Step - 4
go to connection Inspector --> select your camera button event of Touch Up Inside and create the event for your button , for e.g

option - 2
if you want to proceed with your imageview I mean you dont want to proceed with UIButton then follow this code
let cameraTap = UITapGestureRecognizer(target: self, action: #selector(cameraTapped))
displayloginimg.isUserInteractionEnabled = true
displayloginimg.addGestureRecognizer(cameraTap)
and handle the event for your imageview
@objc func cameraTapped() {
// open your camera controller here
}
edited Nov 19 at 9:25
answered Nov 19 at 9:01
Anbu.karthik
59.5k15121111
59.5k15121111
add a comment |
add a comment |
up vote
6
down vote
You can achieve this functionality on UIImageView using UITapGestureRecognizer.
Use below code in your viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
let tapGetsure = UITapGestureRecognizer(target: self,
action: #selector(self.openCamer))
tapGetsure.numberOfTapsRequired = 1
loginimagebtn.gestureRecognizers = tapGetsure
loginimagebtn.isUserInteractionEnabled = true
}
Hi sir...can you tell me how to open front camera by default and please check myopenCamer()function
– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
|
show 1 more comment
up vote
6
down vote
You can achieve this functionality on UIImageView using UITapGestureRecognizer.
Use below code in your viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
let tapGetsure = UITapGestureRecognizer(target: self,
action: #selector(self.openCamer))
tapGetsure.numberOfTapsRequired = 1
loginimagebtn.gestureRecognizers = tapGetsure
loginimagebtn.isUserInteractionEnabled = true
}
Hi sir...can you tell me how to open front camera by default and please check myopenCamer()function
– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
|
show 1 more comment
up vote
6
down vote
up vote
6
down vote
You can achieve this functionality on UIImageView using UITapGestureRecognizer.
Use below code in your viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
let tapGetsure = UITapGestureRecognizer(target: self,
action: #selector(self.openCamer))
tapGetsure.numberOfTapsRequired = 1
loginimagebtn.gestureRecognizers = tapGetsure
loginimagebtn.isUserInteractionEnabled = true
}
You can achieve this functionality on UIImageView using UITapGestureRecognizer.
Use below code in your viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
let tapGetsure = UITapGestureRecognizer(target: self,
action: #selector(self.openCamer))
tapGetsure.numberOfTapsRequired = 1
loginimagebtn.gestureRecognizers = tapGetsure
loginimagebtn.isUserInteractionEnabled = true
}
answered Nov 19 at 9:02
HPM
3069
3069
Hi sir...can you tell me how to open front camera by default and please check myopenCamer()function
– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
|
show 1 more comment
Hi sir...can you tell me how to open front camera by default and please check myopenCamer()function
– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
Hi sir...can you tell me how to open front camera by default and please check my
openCamer() function– Gowthaman M
Nov 19 at 11:05
Hi sir...can you tell me how to open front camera by default and please check my
openCamer() function– Gowthaman M
Nov 19 at 11:05
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
@GowthamanM Use imagePicker.cameraDevice = .front Thats all!!!
– HPM
Nov 19 at 11:10
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
thank you sir let me check once
– Gowthaman M
Nov 19 at 11:12
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
sry sir....where to keep this line,,,I kept wrong place I think so for it's NSInvalidArgumentException error please hel
– Gowthaman M
Nov 19 at 11:16
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
@GowthamanM Keep this after imagePicker.sourceType = UIImagePickerControllerSourceType.camera. Make sure you have added camera permission key in info.plist NSCameraUsageDescription
– HPM
Nov 19 at 11:18
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371058%2fhow-to-create-imageview-click-event-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
create the UIbutton (use setImage property) instead of UIimageview
– Anbu.karthik
Nov 19 at 8:49
@Anbu.karthik Thanks for you suggestion sir..let me check
– Gowthaman M
Nov 19 at 8:50
are you want only camera or else
– Anbu.karthik
Nov 19 at 8:50
@Anbu.karthik yes sir...I have code how to open camera take photos no pbm...I need botton click for imageview
– Gowthaman M
Nov 19 at 8:51
1
@Denis that is not fair. He says he is new to iOS. Reputation is not the benchmark for knowledge. You would also probably do the same if you were to code in Android or any other technology you are new to.
– Rakesha Shastri
Nov 19 at 9:19