Roei Nadam
Roei Nadam

Reputation: 1780

How can I get x,y Position in parent view controller Objective c

I a have UIView1 that hold a child UIView2,UIView2 hold a child UILabel.

Is it possible to get x,y of that UILabel depending onUIView1.

I tried to work with convertPoint without success.

Upvotes: 1

Views: 570

Answers (2)

Jaimish
Jaimish

Reputation: 629

Try this out!

CGRect NewFrame = [View1 convertRect:YourLabel.frame fromView:View2];

check your NewFrame according to first view.

CGFloat Xposition = NewFrame.frame.origin.x; 
CGFloat Yposition = NewFrame.frame.origin.y;

Upvotes: 3

Nikita Ermolenko
Nikita Ermolenko

Reputation: 2259

UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 10, 10)];
[view1 addSubview:view2];
[view2 addSubview:label];


CGRect rect = [label.superview convertRect:label.frame toView:view1];

Upvotes: 1

Related Questions