La construcción de la respuesta por @split ...
La respuesta es fantástica, pero no tiene en cuenta el hecho de que el botón puede tener la imagen personalizada y inserciones de borde de título que se establecen de antemano (por ejemplo, en el guión gráfico).
Por ejemplo, es posible que desee que la imagen tenga un relleno de la parte superior e inferior del contenedor, pero aún mueva la imagen hacia el lado derecho del botón.
me extendió el concepto con este método: -
- (void) moveImageToRightSide {
[self sizeToFit];
CGFloat titleWidth = self.titleLabel.frame.size.width;
CGFloat imageWidth = self.imageView.frame.size.width;
CGFloat gapWidth = self.frame.size.width - titleWidth - imageWidth;
self.titleEdgeInsets = UIEdgeInsetsMake(self.titleEdgeInsets.top,
-imageWidth + self.titleEdgeInsets.left,
self.titleEdgeInsets.bottom,
imageWidth - self.titleEdgeInsets.right);
self.imageEdgeInsets = UIEdgeInsetsMake(self.imageEdgeInsets.top,
titleWidth + self.imageEdgeInsets.left + gapWidth,
self.imageEdgeInsets.bottom,
-titleWidth + self.imageEdgeInsets.right - gapWidth);
}
También puede usar Interface Builder. Mira mi respuesta aquí: http://stackoverflow.com/questions/2765024/how-to-set-the-title-as-left-alignment-in-the-uibutton/22725345#22725345 – n8tr
Solo usa esta subclase con algunas filas de código: https://github.com/k06a/RTLButton – k06a