How do I scale a UIButton's imageView?
Posted
by vcLwei
on Stack Overflow
See other posts from Stack Overflow
or by vcLwei
Published on 2009-12-24T08:09:16Z
Indexed on
2010/03/17
3:31 UTC
Read the original article
Hit count: 1007
Hey guys! I create a UIButton instance(named "button") with a image use [UIButton setImage:forState:] function, the button.frame is larger than the image's size. Now I want to scale this button's image smaller. I had tried to change button.imageView.frame, button.imageView.bounds and button.imageView.contentMode, but all seem ineffective.
Hopefully someone can help me how to scale a UIButton's imageView.Thanks!
my create UIButton instance code:
UIButton *button = [[UIButton alloc] init];
[button setImage:image forState:UIControlStateNormal];
my try to scale the image code:
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.bounds = CGRectMake(0, 0, 70, 70);
and:
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
button.imageView.frame = CGRectMake(0, 0, 70, 70);
© Stack Overflow or respective owner