Reputation: 1780
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
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
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