为什么我看不到按钮?

时间:2015-08-21 01:34:45

标签: objective-c uibutton

我正在为按钮设置图像但它没有显示出来。 据我所知,将其设置为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);

我的代码出了什么问题?

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

原来如果你没有设置它的框架,它就不会出现...... 我认为这是因为UIImageView不需要框架设置,不知怎的,因为我设置了一个图像..认为它的工作方式相同但没有。