Reputation: 1137
I have a UIButton over a UIImageView. I want the button to adjust its size to fit the imageview. I tried a few different ways but can't get it. Anyone know how to do this?
Upvotes: 0
Views: 1118
Reputation: 244
Try this
[btn sizeThatFits:CGSizeMake(img.size.width, img.size.height)];
Upvotes: 0
Reputation: 45
you can use--
UIImage *img = [UIImage imageNamed:@"7.png"];// image to be use
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];// set button frame accordingly.
Upvotes: 0
Reputation: 40193
You can add some padding like this:
NSInteger padding = 10;
CGRect newFrame = myImageView.bounds;
newFrame.origin.x += padding / 2.0;
newFrame.origin.y += padding / 2.0;
newFrame.size.width -= padding;
newFrame.size.height -= padding;
myButton.frame = newFrame;
Upvotes: 1
Reputation: 1401
Just make a custom button with an image-view in Interface-Builder.
Upvotes: 0