Compressing the picture, the size of the picture is inconsistent with the width we expect, we can handle it as we want it to be wide.
Pass in the picture you want to change, and the new size
-(uiimage*) Imagewithimage: (uiimage*) Image scaledtosize: (cgsize) newsize{//Create a graphics image contextUigraphicsbeginimagecontext (newSize);//// new Size[image Drawinrect:cgrectmake (0,0// Get the new image from the contextuiimage* newimage =// End the Context// Return the new Image. NewImage;}
When a button comes with a imageview, if the picture is automatically compressed, it causes distortion (sometimes not as small as we expect). If I'm in iOS learning-uibutton's ImageView and Titlelabel
Wide high enough is no problem, but I put the button of the Titlelabel.font set Small (12), Wide height set small (height of 30 or less) when there is a problem, is not think the picture behind is too big,
And the picture of the width of the high and not directly change, then we can first put the picture to do a small point, in addition on OK.
UIImage *buttonimage = [UIImage imagenamed:image]; // compress picture size buttonimage = [self imagewithimage:buttonimage scaledtosize:cgsizemake ()]; CGFloat buttonimageviewwidth = cgimagegetwidth (buttonimage.cgimage); CGFloat buttonimageviewheight = cgimagegetheight (buttonimage.cgimage); NSString *buttontitle = title; Uifont *buttontitlefont = [Uifont boldsystemfontofsize:12.0f];
iOS Learning-compress pictures (change the width of the picture)