开发者

UIButton image gets distorted

I'm trying to make my UIButton on my Navigation Controller bar. However, when I try to do this my image get's开发者_JAVA百科 distorted.

Here's the code that I'm using:

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];

Any help would be appreciated, I'm on the brink of madness, lol. Thanks


Never-mind, I finally figured it out. lol... you have to use CGRectMake differently depending on if your adding the button as an item or not.

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

90 stretches the image to the needed length.

Make sure you don't add the sampleButton to the nav bar as an item to make the above code won't work like needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜