开发者

How do I resize a UIImageView in the '.m'

I have a UIImageView that I want to resize when you press a button. I haven't been able to find a开发者_C百科ny on other forums or sources.

Any help appreciated,

user826671


Let me google it for you http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/


I have made a sample using slider control. You can activate this slider on your button press and use it to increase or decrease the size of the images https://github.com/manishnath/Code/tree/master/zommin


-(void) onButtonClick { CGRect frameRect = temp.frame; //temp ur UIMAGEVIEW

 frameRect.size.width= your_width;

 frameRect.size.height= height;

 temp.frame=frameRect;

}


If its about UIImage, you can do it by this way. For UIImageView you can change its frame size.

- (UIImage *) resizeImage:(UIImage *)image newWidth:(CGFloat)width 
              newHeight: (CGFloat)height 
{
    CGRect area = CGRectMake(0, 0, width,height);
    CGSize size = area.size;

    UIGraphicsBeginImageContext(size);  
    [image drawInRect:area];    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;    
}


If you want to resize the image view itself, do like

CGRect newRect = imageView.frame;
newRect.size.width = reqWidth;
newRect.size.height = reqHeight;
imageView.frame = newRect;

The image will also be resized if the imageview has the contentMode property UIViewContentModeScaleAspectFit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜