Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 按钮图像失真_Iphone_Objective C_Cocoa Touch - Fatal编程技术网

Iphone 按钮图像失真

Iphone 按钮图像失真,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我正在尝试在导航控制器栏上创建UIButton。然而,当我尝试这样做时,我的图像被扭曲了 以下是我正在使用的代码: UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom]; [sampleButton setTitle:@"Title" forState:UIControlStateNormal]; [sampleButton setBackgroundImage:[[UIImage imageNamed:@"b

我正在尝试在导航控制器栏上创建UIButton。然而,当我尝试这样做时,我的图像被扭曲了

以下是我正在使用的代码:

UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setTitle:@"Title" forState:UIControlStateNormal];
[sampleButton setBackgroundImage:[[UIImage imageNamed:@"but.png"] [sampleButton addTarget:self action:@selector(pushNav)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:sampleButton];

任何帮助都将不胜感激,我快疯了,哈哈。谢谢

没关系,我终于明白了。英雄联盟根据是否将按钮添加为项目,您必须使用不同的CGRectMake

[sampleButton setFrame:CGRectMake(0,32,90,32)];
90将图像拉伸到所需的长度


确保不要将sampleButton作为一项添加到导航栏,以使上述代码无法正常工作

如果你自己回答,你应该为将来的读者提供答案。