Normaly you should use contentMode
(in this case UIViewContentModeScaleAspectFit
) every UIView subclass have this property usually you might use it to UIImageView
. But i'm almost sure that does not work with UIBarButtonItem
. Try, but you might hit a wall.
If my prediction was true you have to resize image programatically:
UIImage *myImage = [UIImage imageNamed:@"fb_share"];
float maximumHeight = 44;
float ratio = maximumHeight/ myImage.size.height;
CGSize imageNewSize = CGSizeMake(myImage.size.width*ratio, maximumHeight);
UIGraphicsBeginImageContextWithOptions(imageNewSize, NO, 0.0);
[myImage drawInRect:CGRectMake(0, 0, imageNewSize.width, imageNewSize.height)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIBarButtonItem *Share = [[UIBarButtonItem alloc] initWithImage:resizedImage style:UIBarButtonItemStyleBordered target:self action:@selector(Share:)];