开发者

How to resize UIButton to fit UIImageView?

I have a UIButton over a UIImageView. I want the button to adjust its size to fit the imageview. I trie开发者_高级运维d a few different ways but can't get it. Anyone know how to do this?


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;


Just make a custom button with an image-view in Interface-Builder.


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.


Try this

    [btn sizeThatFits:CGSizeMake(img.size.width, img.size.height)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜