ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Mobile Application Development 2
    COMP4126
    Progress0 / 38 topics
    Topics
    1. Creating an iOS App: Understanding Xcode2. Using the Xcode interface builder and objects library3. Understanding view hierarchy and creating a custom app icon4. Outlets, Actions, and Views: Understanding outlets and actions5. Using text fields, buttons, labels, web views, and page controllers6. Using views with subviews and creating views using code7. Using View Controllers: Working with the single view template8. Exploring the app delegate and adding new view controllers9. Transitioning between multiple view controllers using animations10. Application Templates: Tabbar and master detail templates11. The iOS Keyboard: Customizing for different inputs12. Adjusting text field behaviors and dismissing the keyboard13. Detecting keyboard activities with notification center14. Using scroll view and responding to keyboard activities programmatically15. Working with Different iOS Devices (iPhone & iPad): Detecting device hardware16. Dynamically adjusting graphical layouts and creating universal apps17. Using Table Views: Understanding UITableView and UITableViewCell18. Working with UITableView data source and delegate19. Master detail template, drill-down menus, and navigation20. Using property lists for data persistence and creating multi-section tables21. Supporting Screen Rotations: Portrait and landscape modes22. Handling device rotation and forcing specific orientation23. Dynamically adjusting layouts based on rotation24. Working with Databases: Importing sqlite3 and creating a database25. Writing tables, inserting records, and bundling a database with your app26. Checking for database existence and reading/displaying data27. Using Animations & Video: NSTimer class and object transformations28. Rotation, scaling, translation, animating image arrays, and playing video29. Accessing Integrated iOS Apps: Email, Safari, and SMS30. Working with camera and photo library31. Using Web Services: Consuming and parsing XML and JSON32. Integrating Twitter and Facebook with iOS apps33. Working with iOS Maps and Location Services: MapKit and MKMapView34. Getting and displaying user location and directional information35. Displaying map annotations, disclosure buttons, and reverse geocoding36. Working with iCloud37. Working with the Accelerometer: Gyroscope and accelerometer38. Outputting sensor data and using the Shake API
    COMP4126›Dynamically adjusting graphical layouts and creating universal apps
    Mobile Application Development 2Topic 16 of 38

    Dynamically adjusting graphical layouts and creating universal apps

    3 minread
    593words
    Beginnerlevel

    📱 Dynamically Adjusting Graphical Layouts & Creating Universal Apps (iOS – Xcode)


    ✅ 1. Definition

    🔹 Dynamic Layout Adjustment

    It means designing an app UI that automatically adapts to different screen sizes, orientations, and devices (iPhone & iPad) without breaking the layout.

    🔹 Universal App

    A universal app is an iOS application that runs properly on both iPhone and iPad using the same codebase, with adaptive layouts.


    🧠 2. Key Concepts

    🔹 Adaptive UI

    • UI that changes based on:

      • Screen size
      • Device type
      • Orientation

    🔹 Auto Layout

    • System that uses constraints to position UI elements dynamically

    🔹 Size Classes

    • Define layout behavior for different devices:

      • Compact width (iPhone)
      • Regular width (iPad)

    🔹 Trait Collection

    • Provides environment info about device (size, orientation, style)

    📐 3. Why Dynamic Layouts Are Needed

    • iPhone screens are small
    • iPad screens are large
    • Landscape and portrait modes differ
    • Users expect smooth UI on all devices

    👉 Without dynamic layout → UI breaks or overlaps


    ⚙️ 4. Techniques for Dynamic Layout Adjustment


    🔹 1. Auto Layout Constraints

    button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    

    🔹 2. Stack Views (Best Practice)

    • Automatically arranges UI elements
    • Adjusts spacing dynamically

    👉 Example:

    • Vertical stack → form fields
    • Horizontal stack → buttons

    🔹 3. Size Classes (Storyboard)

    Device Width Height
    iPhone Compact Regular
    iPad Regular Regular

    🔹 4. Safe Area Layout

    Ensures UI does not overlap:

    • Notch
    • Home indicator
    • Status bar

    🔹 5. Programmatic Layout Adjustment

    if UIDevice.current.userInterfaceIdiom == .pad {
        print("iPad layout")
    } else {
        print("iPhone layout")
    }
    

    🏗️ 5. Creating a Universal App


    🔹 Step 1: Choose Universal App

    • In Xcode project setup:

      • Select Universal (iPhone + iPad)

    🔹 Step 2: Use Auto Layout

    • Avoid fixed frames
    • Use constraints for all UI elements

    🔹 Step 3: Design Adaptive UI

    Example:

    • iPhone → Single column layout
    • iPad → Two column layout

    🔹 Step 4: Use Size Classes

    In storyboard:

    • Compact width → iPhone design
    • Regular width → iPad design

    🔹 Step 5: Test on Devices

    • iPhone simulator
    • iPad simulator
    • Different orientations

    📊 6. Diagram Description (for Exams)

    Draw:

             Universal App
            /            \
         iPhone         iPad
     (Compact UI)   (Expanded UI)
            \            /
         Auto Layout + Size Classes
    

    💡 7. Example

    🎯 Login Screen

    Device Layout
    iPhone Full screen form
    iPad Centered form with side image
    if UIDevice.current.userInterfaceIdiom == .pad {
        print("Load iPad layout")
    } else {
        print("Load iPhone layout")
    }
    

    📌 8. Important Rules / Tips

    • Always use Auto Layout (never fixed frames)
    • Use Stack Views for flexible UI
    • Design for both orientations
    • Use Safe Area constraints
    • Test on multiple simulators

    ⚠️ 9. Common Mistakes

    • ❌ Fixed screen sizes (breaks on iPad)
    • ❌ Ignoring landscape mode
    • ❌ Not using Safe Area
    • ❌ Overusing device-specific code
    • ❌ Poor constraint setup

    🧠 10. Best Practices

    • Use adaptive UI (Auto Layout + Size Classes)
    • Keep UI simple and scalable
    • Prefer stack views for forms
    • Avoid hardcoding positions
    • Test across devices frequently

    📝 11. Likely Exam Questions

    1. What is a universal app in iOS?
    2. Explain dynamic layout adjustment.
    3. What is Auto Layout?
    4. Why are size classes used?
    5. How do iPhone and iPad layouts differ?
    6. What is the role of Safe Area?
    7. How do you create adaptive UI in Xcode?
    8. Write code to detect iPad or iPhone.
    9. Explain Stack Views with example.

    📚 12. Quick Revision Summary

    • Dynamic layout = UI adapts to screen/device

    • Universal app runs on iPhone + iPad

    • Key tools:

      • Auto Layout
      • Size Classes
      • Stack Views
      • Safe Area
    • iPhone → compact UI

    • iPad → expanded UI

    • Always test on multiple devices


    Previous topic 15
    Working with Different iOS Devices (iPhone & iPad): Detecting device hardware
    Next topic 17
    Using Table Views: Understanding UITableView and UITableViewCell

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time3 min
      Word count593
      Code examples0
      DifficultyBeginner