0

我有一个图像视图。我需要将 imageView 的大小限制为白色背景 imageOnly。图像在右、左和上边距之间紧密结合。我对如何在底部进行操作感到困惑,因此图像必须仅适合白色背景。我怎么做 ? http://i.stack.imgur.com/ztvQe.png

我正在使用的代码

 _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 240,175,205)];

框架宽高为205*205

4

3 回答 3

1

您可以将 imageView 添加为具有白色背景的视图的子视图。

UIView *whiteBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(25,240,205,205)];
CGSize whiteSize = whiteBackgroundView.frame.size;
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,size.width,size.height)];
[whiteBackgroundView addSubview:_imageView];

在示例中,您的 imageView 将完全适合白色背景视图的大小。

于 2012-11-28T10:36:35.920 回答
1

试试这个

UIView *productView  = [[UIView alloc]initWithFrame:CGRectMake(25, 240,225,225)];
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,205,205)];
    _imageView.clipsToBounds =YES;
    [productView addSubview:_imageView];
    [self.view addSubview:ImageBackview];
于 2012-11-28T10:41:44.570 回答
0

只需创建一个视图并在其中添加此图像,例如使用下面的代码..

 UIView *ImageBackview = [[UIView alloc]initWithFrame:CGRectMake(25, 240,225,225)];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,205,205)];
[ImageBackview addSubview:_imageView];
[self.view addSubview:ImageBackview];
于 2012-11-28T10:23:40.383 回答