perhaps? 2008-10-09 01:58 采纳率: 66.7%
浏览 314

如何按比例缩放 UIImageView?

I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width.

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;

The image did get resized but the position is not at the top left. What is the best approach to scaling image/imageView and how do I correct the position?

转载于:https://stackoverflow.com/questions/185652/how-to-scale-a-uiimageview-proportionally

  • 写回答

16条回答 默认 最新

  • bug^君 2008-10-09 03:04
    关注

    I think you can do something like

    image.center = [[imageView window] center];
    
    评论

报告相同问题?