![](/img/trans.png)
[英]How to resize a UIImageView to fit the underlying image without moving it?
[英]How to resize UIButton to fit UIImageView?
我在UIImageView上有一個UIButton。 我希望按鈕調整其大小以適合imageview。 我嘗試了幾種不同的方法,但無法實現。 有人知道怎么做嗎?
您可以像這樣添加一些填充:
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;
嘗試這個
[btn sizeThatFits:CGSizeMake(img.size.width, img.size.height)];
只需在Interface-Builder中創建一個帶有圖像視圖的自定義按鈕即可。
您可以使用 -
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.