After testing, if the text length of the button change, will cause the picture position changes, after several changes uiedgeinsets value also did not achieve the desired effect, the final adoption of integrated UIButton class, rewrite layoutsubviews function implementation, special results recorded, For follow-up review
| 123456789101112131415161718 |
-(void)layoutSubviews { [super layoutSubviews]; // Center image CGPoint center = self.imageView.center; center.x = self.frame.size.width/2; center.y = self.imageView.frame.size.height/2; self.imageView.center = center; //Center text CGRect newFrame = [self titleLabel].frame; newFrame.origin.x = 0; newFrame.origin.y = self.imageView.frame.size.height + 5; newFrame.size.width = self.frame.size.width; self.titleLabel.frame = newFrame; self.titleLabel.textAlignment = UITextAlignmentCenter;} |
By rewriting, reset the ImageView center and the Titlelabel frame to solve the above problem.
IOS UIButton Set Picture text vertical arrangement