π± Understanding View Hierarchy & Creating a Custom App Icon (iOS β Xcode)
π§© PART 1: Understanding View Hierarchy
β
1. Definition
View Hierarchy is the arrangement of UI elements (views) in a parentβchild structure in an iOS app.
Each screen is made of multiple views organized in layers, where one view can contain other views.
π§ 2. Key Concepts
πΉ View
- A rectangular area on screen (e.g., button, label, image)
πΉ Superview
- The parent view that contains other views
πΉ Subview
- A child view inside another view
πΉ Root View
- The main view of a screen, controlled by a View Controller
ποΈ 3. Structure of View Hierarchy
Example:
Main View (Root View)
β
βββ Label
βββ Button
βββ Image View
π Here:
- Main View = Superview
- Label, Button, Image = Subviews
π 4. Diagram Description (for Exams)
Draw a tree structure:
-
Top: Root View
-
Branches:
- Label
- Button
- Image View
Show arrows from parent to child.
βοΈ 5. How View Hierarchy Works in Xcode
Step 1: Open Storyboard
Step 2: Use Document Outline
- Located on the left side
- Displays hierarchical structure of views
Step 3: Add UI Elements
- Drag elements from Objects Library
Step 4: Arrange Views
- Drag elements in outline to change hierarchy
Step 5: Manage Layering
- Top views overlap lower ones
- Order affects visibility
π 6. Important Rules
- A subview cannot exist without a superview
- Position is relative to its parent view
- Hidden parent β all child views hidden
- Use hierarchy for better UI organization
π‘ 7. Example
Login Screen Hierarchy:
View
β
βββ Logo Image
βββ Username TextField
βββ Password TextField
βββ Login Button
π¨ PART 2: Creating a Custom App Icon
β
1. Definition
An App Icon is the small image that represents an app on the home screen of an iPhone or iPad.
π§ 2. Key Concepts
πΉ AppIcon Asset
- A set of images in different sizes stored in Xcode
πΉ Asset Catalog
- Folder in Xcode (
Assets.xcassets) where images and icons are stored
πΉ Required Sizes
Different devices require different icon sizes:
- 20x20
- 29x29
- 40x40
- 60x60
- 1024x1024 (App Store)
βοΈ 3. Steps to Create a Custom App Icon
Step 1: Design Icon
-
Use tools like:
-
Keep design:
- Simple
- Clear
- No text (recommended)
Step 2: Generate Icon Sizes
- Use online tools or export multiple sizes manually
Step 3: Open Asset Catalog
- In Xcode β Open
Assets.xcassets
- Click AppIcon
Step 4: Add Icons
- Drag and drop images into correct size slots
Step 5: Set App Icon
- Xcode automatically uses AppIcon set
Step 6: Run App
- Icon appears in simulator/home screen
π 4. Diagram Description (for Exams)
Draw:
- Grid of icon placeholders (AppIcon slots)
- Label different sizes like 60x60, 1024x1024
π 5. Important Rules / Tips
- Use PNG format
- Do NOT add transparency (for App Store icon)
- Maintain consistent design across sizes
- Follow Apple Human Interface Guidelines
- Use high resolution (1024Γ1024)
π‘ 6. Example
Simple App Icon Idea:
- Blue background
- White chat bubble icon
- Clean and minimal design
π 7. Likely Exam Questions
- Define view hierarchy in iOS.
- Differentiate between superview and subview.
- Explain how view hierarchy is managed in Xcode.
- Draw and explain a view hierarchy diagram.
- What is an app icon?
- Explain steps to create a custom app icon in Xcode.
- What is Asset Catalog?
- Why are multiple icon sizes required?
- Write rules for designing a good app icon.
π 8. Quick Revision Summary
πΉ View Hierarchy
- Parent-child structure of UI elements
- Root View β Superview β Subviews
- Managed using Document Outline
- Controls layout and visibility
πΉ App Icon
- Represents app on device
- Stored in Assets.xcassets
- Requires multiple sizes
- Must be simple, clear, high-quality