相关疑难解决方法(0)

如何按比例缩放UIImageView?

我有一个UIImageView,目标是通过给它一个高度或宽度按比例缩小它.

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

//Add image view
[self.view addSubview:imageView];   

//set contentMode to scale aspect to fit
imageView.contentMode = UIViewContentModeScaleAspectFit;

//change width of frame
CGRect frame = imageView.frame;
frame.size.width = 100;
imageView.frame = frame;
Run Code Online (Sandbox Code Playgroud)

图像确实调整了大小但位置不在左上角.缩放image/imageView的最佳方法是什么?如何更正位置?

cocoa-touch objective-c

338
推荐指数
13
解决办法
33万
查看次数

标签 统计

cocoa-touch ×1

objective-c ×1