Objective c 非视网膜显示器上扭曲的自定义导航按钮(使用可拉伸图像方法)

Objective c 非视网膜显示器上扭曲的自定义导航按钮(使用可拉伸图像方法),objective-c,ios,button,uinavigationbar,retina-display,Objective C,Ios,Button,Uinavigationbar,Retina Display,我通过以下代码将自定义导航按钮添加到导航栏中 //Instance method in CustomNavButton Class -(UIButton*)setupButtonWithImage:(UIImage*)image andFrame:(CGRect)frame { UIButton *button = [[[UIButton alloc]initWithFrame:frame]autorelease]; UIImageView *imageView = [[UII

我通过以下代码将自定义导航按钮添加到导航栏中

//Instance method in CustomNavButton Class

-(UIButton*)setupButtonWithImage:(UIImage*)image andFrame:(CGRect)frame
{
    UIButton *button = [[[UIButton alloc]initWithFrame:frame]autorelease];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width-20)/2, (frame.size.height-20)/2, 20, 20)];
    imageView.image = image;

    UIImage *buttonImageNormal = [UIImage imageNamed:@"customBtn_black"];
    UIImage *stretchableButtonImageNormal = [buttonImageNormal
                                         stretchableImageWithLeftCapWidth:12 topCapHeight:0];

    button.titleLabel.font = [UIFont boldSystemFontOfSize:12];
    [button setBackgroundImage:stretchableButtonImageNormal
                  forState:UIControlStateNormal];

    [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [button addSubview:imageView];

    return button;

}

//Call CustomNavButton and add to Navbar
- (void)viewDidLoad
{
    [super viewDidLoad];
    //Add left invite friends button 
    CustomNavButton *leftButton = [[CustomNavButton alloc]initWithImage:[UIImage imageNamed:@"friends_1"] andFrame:CGRectMake(0, 0, 40, 32)];
    [leftButton.customNavButton addTarget:self action:@selector(inviteButtonPressed) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithCustomView:leftButton];

    self.navigationItem.leftBarButtonItem = leftBarButton;
    [leftButton release];

}
导航按钮在我的iPhone上显示良好(IOS5带有视网膜显示器)

但是,我的模拟器(或非视网膜显示器)上的按钮看起来失真

我如何解决这个问题?即使对于非视网膜显示器,如何正确显示按钮

请注意,我也为此创建了@2x按钮

编辑:

这似乎是一个与图像拉伸有关的问题

UIImage *stretchableButtonImageNormal = [buttonImageNormal
                                     stretchableImageWithLeftCapWidth:12 topCapHeight:0];
如果我将leftCapWidth值更改为0,则模拟器上的按钮看起来更好(但仍然不好)

但这样做会使我的视网膜显示按钮看起来有点扭曲(好像我赢不了)


有人能告诉我问题是否真的在这里,以及我如何改变这些值,使其在视网膜和非视网膜显示器上都能正常工作吗?

您有两个文件吗?MyImage.png和MyImage@2x.png? 看起来系统正试图通过缩小@2x文件的大小来调整它的大小,这通常会在简单地缩小它时导致一些像这样的锯齿


MyImage.png的大小应为MyImage@2x.png.

您没有设置文件格式.png或任何您有的格式。正如Chris所说,您需要两个文件:常规文件和@2x。

我正在使用基础图像,并使用UIImage*StretcableButtonimageNormal=[buttonImageNormal StretcableImagewithLeftCapWidth:12 topCapHeight:0]对其进行拉伸;拉伸部分似乎是导致问题的原因,但我不确定如何解决它。是的,我选择的左帽宽度的像素数似乎是导致问题的原因