iOS_Advanced
iOS_Advanced
Protocol-Oriented Programming
protocol Drawable { func draw() } struct Circle: Drawable { func draw() { print("Drawing a
circle") } }
CustomLabel
import UIKit
CustomViewWithShadow
import UIKit
publisher1.send(1)
publisher2.send(2)
advertisement
Implementing MVVM Architecture Tutorial
The Model-View-ViewModel (MVVM) architecture pattern is a design pattern that helps separate
concerns in your iOS applications, promoting a clear organization of code. The Model represents the
data and business logic, the View is the user interface that displays the data, and the ViewModel acts
as an intermediary that converts data from the Model into a format usable by the View, allowing for easy
data binding and updates.
Copy
Simple MVVM Example
import SwiftUI
struct Task {
var title: String
var isCompleted: Bool
}
Scaling Animation
UIView.animate(withDuration: 0.5) {
myView.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
}
Rotation Animation
UIView.animate(withDuration: 1.0) {
myView.transform = CGAffineTransform(rotationAngle: .pi)
}
Moving Animation
UIView.animate(withDuration: 1.0) {
myView.center = CGPoint(x: 200, y: 200)
}
Bouncing Animation
UIView.animate(withDuration: 0.5,
delay: 0,
usingSpringWithDamping: 0.5,
initialSpringVelocity: 0.5,
options: .curveEaseInOut,
animations: {
myView.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
},
completion: { _ in
myView.transform = CGAffineTransform.identity
})
Using UIAccessibilityTraits
button.accessibilityTraits = .button
Accessibility Hint
button.accessibilityHint = "Double-tap to submit the form"