Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使矩形等于图像视图_Iphone_Objective C_Ios_Xcode - Fatal编程技术网

Iphone 使矩形等于图像视图

Iphone 使矩形等于图像视图,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我有一个图像视图。我需要将imageView的大小限制为仅白色背景图像。图像在右、左和上边距之间紧密绑定。我不知道如何做在底部,这样的图像必须适合在白色背景只。我该怎么做? 我正在使用的代码 _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 240,175,205)]; 框架宽度和高度为205*205只需创建一个视图并将此图像添加到其中,例如使用下面的代码 UIView *ImageBackview = [[UI

我有一个图像视图。我需要将imageView的大小限制为仅白色背景图像。图像在右、左和上边距之间紧密绑定。我不知道如何做在底部,这样的图像必须适合在白色背景只。我该怎么做?

我正在使用的代码

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

框架宽度和高度为205*205

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

 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];

可以将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];
在本例中,您的图像视图将完全适合白色背景视图的大小。

试试这个

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];