Reputation: 1564
I have a UIButton with size of 200*200 and I have a image with size of 50*50. I want to horizontally align the image inside imageview, so that image occupy a frame of (150,75,50,50)
. I tried [button.imageview setContentMode:UIViewContentModeRight]
but this does not work. How can I align image ?
Upvotes: 1
Views: 618
Reputation: 27448
You can manage this scenario something like this,
Take UIView
of size 200x200
.
Then add imageview of size 50x50
to that view with frame (150,75,50,50)
.
And set that image to this imageview. so, your outer view have desired blank space and your imageview fully filled by image and it will looks like image view having image set at right side.
hope this will help :)
Upvotes: 0
Reputation: 288
You can get size of the image so programmatically adjust the frame according to you need. In your case x position+width should the width of the view there you need to keep image.
Upvotes: 0
Reputation: 334
I know it's been a while since February, but I just encountered the same need in the app I am developing.
I solved it using a custom UIImageView which can be easily integrated into your existing code (it's a drop-in replacement of UIImageView).
You can find the class on github, along with an example: https://github.com/reydanro/UIImageViewAligned
Hope this helps you on your project.
Upvotes: 1