UIImage on UIButton是模糊的



我一直在与这个问题作斗争,我想在UIButton上显示一个png,但由于某种原因,图像最终在模拟器和物理设备上都非常模糊。我尝试使用所有不同尺寸的图像,所有图像均为 326 ppi(在 xcode 中验证),但没有一个看起来正确。我还尝试使用 UIGraphics 调整应用程序中的图像大小,但问题仍然存在。以下是设置按钮的代码:

//MIRROR BUTTON
    _mirrorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //_mirrorButton.frame = CGRectMake(buttonWidth, 0.0f, buttonWidth, buttonHeight);
    _mirrorButton.frame = CGRectMake(64, 0, 64, 50);
    UIImage *mirrorImage;

    _mirrorButton.backgroundColor = [MessageView getUserColor];
    mirrorImage = [UIImage imageNamed:@"mirror.png"];
    [_mirrorButton setImage:mirrorImage forState:UIControlStateNormal];
    [_mirrorButton addTarget:self action:@selector(mirrorPressed) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_mirrorButton];

UIButton 和图像的高度都应该为 50 像素。我的UIButton的框架是完整的,图像甚至具有均匀的像素宽度和高度(有人说这将有助于居中)。任何煽动将不胜感激。谢谢。

从我阅读的内容来看,我认为您可能会将 50 像素与 50 点混淆。帧通常以点而不是像素为单位,您可以在此处看到差异

所以基本上,如果你使用50点高的框架,在带有视网膜屏幕的设备中,你将需要一个100px高的图像,然后它不应该再看起来模糊了

最新更新