【发布时间】:2013-04-24 21:35:59
【问题描述】:
我有一个UIImageView 的视图。我正在从我的服务器中检索 300 像素宽和 100 像素高的图像。但是,当我将图像插入我的UIImageView 时,图像会被拉伸到图像视图的大小。
代码viewDidLoad:
id path = @"URL TO IMAGE";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
CGRect frame = [imageView frame];
frame.size.width = 300;
frame.size.height = 100;
[imageView setFrame:frame];
self.imageView.image = img;
但是,UIImageView 的大小不会更改为我上面代码的第 6 行和第 7 行中的值。
感谢任何建议,我是 Objective-C 的新手。
.h:
#import <UIKit/UIKit.h>
@interface detailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
【问题讨论】:
标签: ios objective-c uiimageview cgrect