请帮助我找到一些解决以下问题的方法。IOS,Xcode我有UIBarItem组件--在工具栏上切换语言的按钮。该条形图具有initeWithImage(UIImage)函数。问题是,当我试图缩放图像时,它变得充满了color...The,对于工具栏来说,图片太大了。我已经手动改变了图片的大小,但是它看起来很难看(我需要缩放)。
我试着解决了这个问题: 1、槽级2.通过帧大小3.以及两者的变化:)
一些代码:
self initWithImage:image //
style: UIBarButtonItemStyleBordered //UIBarButtonItemStylePlain
target:target
action:action
UIImage *image;
image = [[UIImage imageNamed:@“image.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];-(UIImage )imageWithImages:(UIImage )image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}拜托,帮帮我。相当简单但很棘手的任务。我已经花了好几个小时.(预先谢谢:)
发布于 2016-03-06 01:58:52
您不应该使用initWithImage方法。如果您想要显示确切的图像,应该使用initWithCustomView方法。
例如:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];如果愿意,可以先缩小图像,然后再将其设置为图像视图。
https://stackoverflow.com/questions/35821335
复制相似问题