简体   繁体   中英

UIView Subclass: Detect the size of a UIView set up in Interface Builder which uses said UIView subclass as a custom class

I have a class called BannerAdView which is a subclass of UIView.

I have a UIView object which I set up in Interface Builder. I used Identity Inspector to set BannerAdView as its custom class.

How can BannerAdView detect the dimensions of the UIView that was set up in Identity Inspector?

self.frame.size.height and self.frame.size.width both return 0.000000

Implement this in BannerAdView :

- (void)awakeFromNib {
    [super awakeFromNib];
    NSLog(@"%@", NSStringFromCGRect(self.frame));
}

You can see dimensions of the UIView.

NSLog(@"My view's frame is: %@", NSStringFromCGRect(myView.frame));

I hope it's will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM