使矩形等于图像视图

时间:2012-11-28 10:18:09

标签: iphone objective-c ios xcode

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

我正在使用的代码

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

框架宽度和高度为205 * 205

3 个答案:

答案 0 :(得分: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将完全符合白色背景视图的大小。

答案 1 :(得分: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];

答案 2 :(得分: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];