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, 2022 in Mobile Development by gaurav
• 23,260 points
1,103 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, 2022 in Mobile Development by gaurav
• 23,260 points
679 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, 2022 in Mobile Development by gaurav
• 23,260 points
687 views
0 votes
1 answer

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

Import Statement : #import<CoreTelephony/CTCarrier.h> #import <CoreTelephony/CTTelephonyNetworkInfo.h> you can get country ...READ MORE

answered Dec 15, 2022 in Mobile Development by gaurav
• 23,260 points
1,200 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, 2022 in Mobile Development by gaurav
• 23,260 points
400 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, 2022 in Mobile Development by gaurav
• 23,260 points
439 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,020 points
1,548 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
1,154 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
644 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
1,773 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