Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS设置UINavigationBar标题中按钮的大小_Iphone_Ios_Objective C_Uinavigationbar - Fatal编程技术网

Iphone iOS设置UINavigationBar标题中按钮的大小

Iphone iOS设置UINavigationBar标题中按钮的大小,iphone,ios,objective-c,uinavigationbar,Iphone,Ios,Objective C,Uinavigationbar,我试图用一个按钮来代替UINavigationBar上的标题。我已经成功地让按钮与自定义图像一起显示,但我很难弄清楚如何调整它的大小。我尝试了一些事情,包括: UIButton *titleButton = [[UIButton alloc]init]; UIImage *settingsButtonImage = [UIImage imageNamed:@"settingsButton2X.png"]; [titleButton addTarget:self action:@selector(

我试图用一个按钮来代替UINavigationBar上的标题。我已经成功地让按钮与自定义图像一起显示,但我很难弄清楚如何调整它的大小。我尝试了一些事情,包括:

UIButton *titleButton = [[UIButton alloc]init];
UIImage *settingsButtonImage = [UIImage imageNamed:@"settingsButton2X.png"];
[titleButton addTarget:self action:@selector(settingsButtonPress:) forControlEvents:UIControlEventTouchDown];
[titleButton setBackgroundImage:settingsButtonImage forState:UIControlStateNormal];
[titleButton setFrame:CGRectMake(0, 0, 20, 20)];
self.navigationItem.titleView = titleButton;
这非常有效,除了导航栏中的结果图像仅在y方向上调整大小,从而产生一种模糊的外观(不幸的是,我无法发布图像来显示这一点,因为我没有声誉-您可能可以在此处看到它:)

我可以使用20 x 20px的图像,它可以正确显示,但在视网膜显示器上看起来是像素化的

所以我的主要问题是:向UINavigationBar的标题区域添加按钮的最佳方式是什么?这个按钮的图像的最佳像素大小是多少?它在旧版iphone屏幕和新的视网膜显示器上看起来都很锐利?(很明显,我对图像的像素大小有些不了解——我认为最好从40x40px或60x60px图像开始)


谢谢你的帮助

你为什么不试试这样的东西:-------


你为什么不试试这样的东西:-------


iphone 32*32的图像大小。视网膜的图像名称应为settingsButton@2x.pngphysics格拉德,你的密码是对的。你的错误是在使用资源。请阅读有关在图像名称中使用@2x的内容。我明白了。非常感谢您为我澄清。iphone 32*32的图像大小。视网膜的图像名称应为settingsButton@2x.pngphysics格拉德,你的密码是对的。你的错误是在使用资源。请阅读有关在图像名称中使用@2x的内容。我明白了。非常感谢你让我明白过来。大力士,谢谢你。那很好用。正是这些小东西一直在吞噬着你。赫拉克勒斯,谢谢你。那很好用。正是这些小东西一直在吞噬着你。
UIButton *titleButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

UIImage *settingsButtonImage = [UIImage imageNamed:@"settingsButton2X.png"];
[titleButton addTarget:self action:@selector(settingsButtonPress:) forControlEvents:UIControlEventTouchDown];
[titleButton setBackgroundImage:settingsButtonImage forState:UIControlStateNormal];
titleButton.center=self.navigationController.navigationBar.center;
titleButton.center=CGPointMake(titleButton.center.x, self.navigationController.navigationBar.frame.size.height/2);
[self.navigationController.navigationBar addSubview:titleButton];