在实现左字右图的需求时发现一下代码在iOS15中失效
[self.detailBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -self.detailBtn.imageView.image.size.width-2, 0, self.detailBtn.imageView.image.size.width+2)];
[self.detailBtn setImageEdgeInsets:UIEdgeInsetsMake(0, self.detailBtn.titleLabel.bounds.size.width+2, 0, -self.detailBtn.titleLabel.bounds.size.width-2)];
研究得知iOS15中引入了UIButtonConfiguration。通过以下代码可以更直观的实现按钮内布局
UIButtonConfiguration *detailBtnConfig = [UIButtonConfiguration plainButtonConfiguration];
detailBtnConfig.contentInsets = NSDirectionalEdgeInsetsMake(0, 0, 0, 0);
detailBtnConfig.imagePlacement = NSDirectionalRectEdgeTrailing;
detailBtnConfig.imagePadding=4.5;
self.detailBtn.configuration= detailBtnConfig;
继而发现在iOS15中按钮文字和图片消失,进入其他界面返回后才出现。经研究发现为xib中设置了style 为plain,改为default后正常显示
网友评论