老是遇到图片在文字的右边问题,今天闲着没事简单的做了一下!
使用的是 imageEdgeInsets 和 titleEdgeInsets 来实现Button的image和title互换位置
1.图片在文字的右边
self.imageEdgeInsets=UIEdgeInsetsMake(0, titleRect.size.width+self.padding,0, -titleRect.size.width-self.padding);
self.titleEdgeInsets=UIEdgeInsetsMake(0, -imageRect.size.width,0, imageRect.size.width);
效果如下
2.图片在文字上面
self.imageEdgeInsets=UIEdgeInsetsMake(-titleRect.size.height/2,titleRect.size.width/2, titleRect.size.height/2, -titleRect.size.width/2);
self.titleEdgeInsets=UIEdgeInsetsMake(imageRect.size.height/2+self.padding, -imageRect.size.width/2, -imageRect.size.height/2-self.padding, imageRect.size.width/2);
过多的就不展示了