botton.imageEdgeInsets = UIEdgeInsetsMake(- (botton.frame.size.height - botton.imageView.frame.size.height)/2, 0, (botton.frame.size.height - botton.imageView.frame.size.height)/2, 0); botton.titleEdgeInsets = UIEdgeInsetsMake(0, - (botton.imageView.frame.size.width/2 + botton.titleLabel.frame.size.width/2), 0, (botton.imageView.frame.size.width/2 + botton.titleLabel.frame.size.width/2));
核心代码:
UIEdgeInsetsMake(top, left, bottom, right);
由于Y轴通过top、bottom控制,在设置偏移量的时候要同时修改,如只修改一边,则偏移量倍数要x2(X轴同解)
时间: 2024-11-05 06:01:42