-(void) layoutsubviews { [super layoutsubviews]; /* super view frame 47:317 --------------- | | | |23:46|imgView | | -------------- | | | | | | | | 46 | | |--|--23 . Center | | */// // center image CGRect rect = self.imageView.frame; rect.size.height=20; rect.size.width=20; //fixed layer height and width, avoid offset, see your project image size self.imageView.frame = rect; cgpoint center = self.imageview.center; cgrect newFrame = [self titleLabel].frame; center.x = self.frame.size.width/2; center.y = self.frame.size.height/2 - newframe.size.height/2; self.imageview.center = center; //Center text newFrame.origin.x = The left distance of the self.imageview.frame.size.width/2 + _spacing/2; //↑ text box is the width of the icon/2 + interval distance/2, because the default layout picture is left, the text is in the right newFrame.origin.y = self.imageview.frame.size.height + self.imageview.frame.origin.y + _spacing; //↑ the top distance of the text box is the y-coordinate of the icon + the height of the picture itself + distance newframe.size.width = self.frame.size.width; self.titlelabel.frame = newframe;}
Overriding the Layoutsubviews method in inheriting from the UIButton class
UIButton vertical arrangement + two intervals