为什么我看不到按钮



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

我的代码有什么问题?

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

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

如果你不设置它的框架,它就不会显示…我假设它会因为UIImageView不需要帧设置因为我在设置一个图像。