Maulik
Maulik

Reputation: 19418

get the height of UIView

I am having trouble in getting UIView's height. I am trying to get the height and (x,y) of my UIView. The view is add as subview of Other view

float y = optionalView.frame.size.height;
    NSLog(@"%.1f",y);

but it always return 0.0 . need guidance.

Thanks...

Upvotes: 14

Views: 43115

Answers (3)

Darius Miliauskas
Darius Miliauskas

Reputation: 3524

However, if the class is UIView itself, then only:

CGFloat height = self.bounds.size.height

Upvotes: 6

civiac
civiac

Reputation: 279

Have you tried this @Maulik?

CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);

Upvotes: 12

Pacu
Pacu

Reputation: 1985

if you want to log it

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

Upvotes: 12

Related Questions