Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the frame of a view inside another view?

I have an UIImageView in the self.view (the main View) and inside it there is a UIButton. I want to know what's the frame of UIButton in self.view not in UIImageView.

like image 395
cyclingIsBetter Avatar asked Nov 10 '11 16:11

cyclingIsBetter


People also ask

How do I get the frame of view in Swift?

swift, override viewDidLoad(). Create a CGRect that will be the frame of a UIView. Next, create an instance of UIView and set its backgroundColor property to blue. Finally, add the UIView as a subview of the view controller's view to make it part of the view hierarchy.

What is a view's frame?

Frame A view's frame ( CGRect ) is the position of its rectangle in the superview 's coordinate system. By default it starts at the top left. Bounds A view's bounds ( CGRect ) expresses a view rectangle in its own coordinate system.

How do you bring a view to the front?

Just one single method will let you to bring your view to the front and the magic words are : myView. bringToFront(); “.

What is bounds in swift?

The bounds rectangle, which describes the view's location and size in its own coordinate system.


1 Answers

I guess you are looking for this method

– convertRect:toView:

// Swift let frame = imageView.convert(button.frame, to: self.view)  // Objective-C CGRect frame = [imageView convertRect:button.frame toView:self.view]; 
like image 130
beryllium Avatar answered Oct 06 '22 12:10

beryllium