HomeiOS Developmentios - Cannot place UIImage by CGRect

ios – Cannot place UIImage by CGRect


I am attempting to construct a UIView of Social Media Person’s Profile and obtained caught proper at first – when including a Person Picture (UIImage) to my UIView. This is the code I am attempting to make use of:

import UIKit

class ProfileHeaderView: UIView {
    
    personal lazy var profileImage: UIImageView = {
        let imageView = UIImageView(picture: UIImage(named: "hipsterCat"))
        
        // Making Picture Spherical
        imageView.layer.cornerRadius = imageView.body.dimension.width / 2
        imageView.clipsToBounds = true
        
        imageView.layer.borderColor = UIColor.white.cgColor
        imageView.layer.borderWidth = 3
                
        return imageView
    }()
    
    override init(body: CGRect) {
        tremendous.init(body: body)
        setupView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        tremendous.init(coder: aDecoder)
        setupView()
    }
    
    personal func setupView() {
        backgroundColor = .lightGray
        addSubview(profileImage)
    }
    
    override func layoutSubviews() {
        tremendous.layoutSubviews()
        
        profileImage.body = CGRect(
            x: bounds.midX - 64,
            y: bounds.midY - 64,
            width: 128,
            peak: 128
        )
    }
}

My process is to make use of CGRect to place UIImage on the superView, but as soon as I run the challenge it simply would not seem on the display (solely mild grey background is there).

UIImageView is all proper, the picture seems when commenting layoutSubviews() override nevertheless it’s not positioned.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments