gpt4 book ai didi

iphone - UIbarbuttonItem 图像看起来拉伸(stretch)/变厚

转载 作者:行者123 更新时间:2023-11-29 13:09:51 25 4
gpt4 key购买 nike

我在工具栏上添加了自定义 UIbarButtonItems。一切都是通过 NIB 文件创建的。我看到图像被拉伸(stretch)了。我的视网膜图像是 20x20 和 40x40。它们是 png 文件,我确保它们不包含任何阴影并使用抗锯齿。目前工具栏看起来像这样。 enter image description here

如果您看到,相同的图像在未添加为 barbuttonItem 而是作为 imageview 添加时显得清晰。我该如何解决这个问题。

最佳答案

您可以尝试在您的 viewDidLoad 方法中创建您的 UIBarButtonItems 吗?

这是我如何处理 UINavigationBar 并且所有图像看起来都很好:

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *rightButtonImage = [UIImage imageNamed:@"img1.png"];
[rightButton setImage:rightButtonImage forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0.0, 7.0, rightButtonImage.size.width, rightButtonImage.size.height);
[rightButton addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:rightButton] autorelease];


UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *leftButtonImage = [UIImage imageNamed:"img2.png"];
[leftButton setImage:leftButtonImage forState:UIControlStateNormal];
leftButton.frame = CGRectMake(10.0, 7.0, leftButtonImage.size.width, leftButtonImage.size.height);
[leftButton addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftButton] autorelease];

method1method2 是无效方法:-(void)method

要在右侧添加 2 个按钮,我会这样做:

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *rightButtonImage = [UIImage imageNamed:@"img3"];
[rightButton setImage:rightButtonImage forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0.0, 7.0, rightButtonImage.size.width, rightButtonImage.size.height);
[rightButton addTarget:self action:@selector(method3) forControlEvents:UIControlEventTouchUpInside];

UIButton *middleRightButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *middleRightButtonImage = [UIImage imageNamed:@"img4"];
[middleRightButton setImage:middleRightButtonImage forState:UIControlStateNormal];
middleRightButton.frame = CGRectMake(0.0, 7.0, middleRightButtonImage.size.width, middleRightButtonImage.size.height);
[middleRightButton addTarget:self action:@selector(method4) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:[[[UIBarButtonItem alloc] initWithCustomView:rightButton] autorelease], [[[UIBarButtonItem alloc] initWithCustomView:middleRightButton] autorelease], nil];

对于 UIToolbar,您必须添加如下项目:

[toolbar setItems:[NSArray arrayWithObject:item1, item2, item3, item4, nil]];

关于iphone - UIbarbuttonItem 图像看起来拉伸(stretch)/变厚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17656194/

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