UIButton图像变形

时间:2011-01-01 20:05:14

标签: iphone objective-c cocoa-touch

我正在尝试在我的导航控制器栏上创建我的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];

任何帮助都会受到赞赏,我正处于疯狂的边缘,哈哈。感谢

1 个答案:

答案 0 :(得分:0)

没关系,我终于明白了。大声笑......你必须以不同的方式使用CGRectMake,具体取决于你是否将按钮添加为项目。

[sampleButton setFrame:CGRectMake(0,32,90,32)];

90将图像拉伸到所需的长度。

确保不将sampleButton作为项添加到导航栏,以使上述代码无法按需运行。

相关问题