UI View

ajith_karuna

AJITHKUMAR K

Posted on December 28, 2022

UI View

UIView can be defined as an object by using which we can create and manage the rectangular area on the screen. We can have any number of views inside a view to create a hierarchical structure of the UIViews.
The UIView is managed by using the methods and properties defined in the UIView class that inherits UIKit.
Views are the fundamentals of iOS application development, and that's why UIView is one of the most used object in the object library. The views are the basic building block of the iOS application, which renders the content within its bounds rectangle and also handles any interaction with the content.

Layout and Sub view management
We can embed one or more subviews into the UIView. The appearance of the subviews can be managed by managing the appearance of the super view.
We can define the auto-layout rules to govern the size and positioning of the view hierarchy on different iOS devices.
Event Handling
A view can respond to the touch and another kind of event since it is the subclass of UIResponder.
We can add the gesture recognizers for the uiview, such as UITapGestureRecognizer.

GestureRecognizer

  • Tap gestures

Tap gestures detect one or more fingers touching the screen briefly. The fingers involved in these gestures must not move significantly from the initial touch points, and you can configure the number of times the fingers must touch the screen.

   let tapped=UITapGestureRecognizer(target: self, action: #selector(IsTapped))
        tapped.numberOfTapsRequired=2
        AppHeader.addGestureRecognizer(tapped)

 @objc func IsTapped(){
        AppHeader.backgroundColor = .green
    }
Enter fullscreen mode Exit fullscreen mode
  • long-press gestures Long-press (also known as press-and-hold) gestures detect one or more fingers (or a stylus) touching the screen for an extended period of time.
 let tapped=UILongPressGestureRecognizer(target: self, action: #selector(IsTapped))
        AppHeader.addGestureRecognizer(tapped)

Enter fullscreen mode Exit fullscreen mode
  • swipe gestures

A swipe gesture occurs when a person moves one or more fingers across the screen in a specific horizontal or vertical direction. Use the UISwipeGestureRecognizer class to detect swipe gestures.

        let swipe=UISwipeGestureRecognizer(target: self, action: #selector(IsTapped))
        swipe.direction = .left
        AppBody.addGestureRecognizer(swipe)

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
ajith_karuna
AJITHKUMAR K

Posted on December 28, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related