How to fetch the width and height of a programatically added view in Swift iOS

0 votes

I have added a UIView and a UIImageView programatically, but I need its width and height. Is it possible to fetch it, if yes, please share how to fetch it.

Code:

let View1: UIView = {
            let viewView = UIView()
            viewView.translatesAutoresizingMaskIntoConstraints = false
            viewView.contentMode = .scaleAspectFit
            print(UserDefaults.standard.bool(forKey: "backgroundColourSelected"))
            if UserDefaults.standard.bool(forKey: "backgroundColourSelected") {
                viewView.backgroundColor = self.viewColor
            }else {
                viewView.backgroundColor = .white
            }
            viewView.clipsToBounds = true
            return viewView
        }()
    
        self.canvasView.addSubview(View1)
        
        View1.centerXAnchor.constraint(equalTo: canvasView.centerXAnchor, constant: 0).isActive = true
        View1.centerYAnchor.constraint(equalTo: canvasView.centerYAnchor, constant: 0).isActive = true
        View1.widthAnchor.constraint(equalTo: canvasView.widthAnchor, constant: 0).isActive = true
        View1.heightAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: aspectRatio).isActive = true

Nov 10 in Mobile Development by gaurav
• 22,040 points
25 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Mobile Development

0 votes
0 answers

How to get original image when we zoom in and zoom out the image in ios

Hi i am beginner in ios and ...READ MORE

Nov 17 in Mobile Development by gaurav
• 22,040 points
14 views
0 votes
0 answers

How to login to a site using POST request? (Swift,iOS)

I want to create an iOS Application ...READ MORE

Nov 9 in Mobile Development by gaurav
• 22,040 points
30 views
0 votes
0 answers

How to get the user's country calling code in iOS?

I am developing an iOS app in ...READ MORE

4 days ago in Mobile Development by gaurav
• 22,040 points
7 views
0 votes
0 answers

Change English Number To Persian Numbers in Text Swift,IOS

Hi How can i replace english numbers ...READ MORE

Nov 8 in Mobile Development by gaurav
• 22,040 points
28 views
0 votes
0 answers

How to receive single tap and hold Remote-Control Event with iOS

I'm looking for my app to listen ...READ MORE

Nov 8 in Mobile Development by gaurav
• 22,040 points
33 views
0 votes
0 answers

How to draw heart shape in UIView (iOS)?

I want to create different shapes. Below ...READ MORE

Nov 10 in Mobile Development by gaurav
• 22,040 points
22 views
0 votes
1 answer

Get User Group in Swift using AWS Cognito

The groups are exposed in the ID ...READ MORE

answered Nov 12, 2018 in AWS by Priyaj
• 58,100 points
951 views
0 votes
1 answer

URL Scheme for iOS Home App

I think you could try doing it ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
498 views
0 votes
1 answer

iOS App : Porting Code to App

If you make a post, missing parameters ...READ MORE

answered Jan 18, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
230 views
0 votes
1 answer

swift for windows? xcode on windows? ?

Hi, @Aminegac, If you’re a little more technically ...READ MORE

answered Dec 4, 2020 in Others by Nikita
685 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP