doyeona
Published in

doyeona

How to make UIView Clickable?

Sometimes you want to make multiple objects in one group and make it clickable. I brought the simplest way to do it!

You can either use TapGestureRecognizer to your label, views, and many other objects or to use stackView 😈

btw, anyone Interested to read my post about TapGestureRecognizer, please click the link below.

For example, when changing the profile, i just want the user to click within the area between the image and the label to do some tasks but how to make them in one group and how will know if the object is clicked or not?

1️⃣ Add View

2️⃣ Inside the View, add Stack View and Button objects. Add the constraints top, bottom, left, right to 0 for each object.

3️⃣ Inside the stackView, add objects (image, label)

4️⃣ Run the code and click it!

Whenever clicking the label or image, it will show you an action. Thank you for reading! 🌱

--

--

--

Daily study logs about iOS development will be updated. Any recommendations or discussions are always welcome

Recommended from Medium

How to share Realm DB with Widget Target on existing project— iOS & Swift

UIKit Animations Are Messy — Here’s Why SwiftUI Can Fix That

Paint splattered across the floor

How to: Add Firebase-auth to SwiftUI 2 (2020)

iOS App Distribution 4 Core Concepts. Make abstract concepts concrete.

Memory Management Part 1: Regions, Types and Leaks

SwiftUI List: Add move, delete, update feature, introducing ‘HANDY’ iOS API to handle list.

App Privacy and Changes in the new version of iOS

How to: Add Firebase to SwiftUI 2 (2020)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Doyeon

Doyeon

Hey! I am currently studying iOS by myself, and wanna be a cool app developer 🕶 please correct me if i’m wrong or if there’s any thing that you wanna share😊✌️

More from Medium

How to Create A Basic API Call in SwiftUI ?

A swift introduction to SWIFT

Intermediate: Let’s us take a tour of Cloud DB in Huawei Mobile Service

Connect 4 Game on iOS (四子棋)