Daily iOS
UIKit

Pinning four corners with constraints

Live coding. Given an [UIImage], how would you build a custom UIView that pins one image to each of its four corners using only constraints in code?

final class CornerImagesView: UIView {
    init(images: [UIImage]) { /* ... */ }
}
How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Create four UIImageViews, and activate each corner's leading/trailing and top/bottom anchors plus size constraints in one NSLayoutConstraint.activate call. Without size constraints they blow up to the image's intrinsic size.

Share a question