UIImage *buttonImg = [button imageForState:UIControlStateNormal];
CGFloat titleWidth = [button.titleLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:18],NSFontAttributeName, nil]].width;
[button setTitleEdgeInsets:UIEdgeInsetsMake(buttonImg.size.height, -buttonImg.size.width, 0, 0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(-15, 0, 0, -titleWidth)];

效果如下。俩个图不对称是因为图片大小不同。

UIButton 图片文字上下对齐

相关文章:

  • 2021-11-12
  • 2022-01-13
  • 2021-11-01
  • 2022-01-08
  • 2021-04-16
  • 2021-12-15
  • 2021-12-06
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-11-26
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案