简体   繁体   中英

center subview according to other subview when both have the same superview

If I have contentView and 2 subviews. I want to center subviewA according to subviewB

subviewA and subviewB have the same superview.

this is what I'm doing now to center subviewA(activity indicator) above uitableview.

self.subViewA.frame = CGRectMake(CGRectGetMidX(self.tableView.frame)-self.subViewA.bounds.size.width/2,
                                                                 CGRectGetMidY(self.tableView.frame)-self.subViewA.bounds.size.height/2,
                                                                 self.subViewA.bounds.size.width,
                                                                 self.subViewA.bounds.size.height);

Is there cleaner/short way ? any method that exist and I'm missing :) ?

I thought maybe there is somthing like : subviewA.frame = centerInOtherFrame(self.subviewB.frame)

您的方法可以简化为

self.subViewA.center = self.tableView.center;

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