2015-08-21 228 views
0

我正在设置一个按钮的图像,它不显示。 据我所知将其设置为backgroundImage会将其拉伸为按钮的大小,因此我宁愿使用setImage来代替。为什么我看不到按钮?

self.mainMapButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[self.mainMapButton setImage:[UIImage imageNamed:@"map_icon"] forState:UIControlStateNormal]; 
[self.tabView addSubview:self.mainMapButton]; 
self.mainMapButton.center = CGPointMake((self.tabView.frame.size.width/4)/2, self.tabView.frame.size.height/2); 

我的代码出了什么问题?

+0

你试过“backgroundImage”吗?它出现了吗? – anhtu

+0

nope。但想出了为什么.. – durazno

+0

也许帧是不正确的 – anhtu

回答

2

也许一个愚蠢的建议,但你不需要设置按钮框?

self.mainMapButton.frame = CGRectMake(100.0, 180.0, 100.0, 40.0); 
+0

是的,我已经想出了我自己现在已经解决了。 – durazno

+0

@durazno,这个答案应该被接受。 – WMios

+0

他在发布我自己的答案的同时发布了这个。所以我不觉得需要,但没关系。 – durazno

0

事实证明,如果你不设置它的框架也不会显示出来...... 我以为它会因为的UIImageView不需要框设置并以某种方式,因为我设置的图像..认为它会同样工作,但没有。

相关问题