gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:24:07 27 4
gpt4 key购买 nike

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

//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 上显示良好(带有 Retina 显示屏的 IOS5)

enter image description here

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

enter image description here

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

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

enter image description here

编辑:

似乎问题与图像的拉伸(stretch)有关
UIImage *stretchableButtonImageNormal = [buttonImageNormal
stretchableImageWithLeftCapWidth:12 topCapHeight:0];

如果我将 leftCapWidth 值更改为 0,模拟器上的按钮看起来会更好(但仍然很糟糕)。

enter image description here

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

任何人都可以建议问题是否确实存在于此,以及我如何更改这些值以使其适用于视网膜和非视网膜显示器?

最佳答案

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

MyImage.png 应该是 MyImage@2x.png 大小的一半。

关于objective-c - 非视网膜显示屏上扭曲的自定义导航按钮(使用可拉伸(stretch)图像方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8793176/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com