我想创建一个停留在屏幕底部的视图。 UIView能正常工作并显示。我试图放置一个UIButton的UIView大小,但按钮不会显示。我把这段代码放到了Swift Playground中,它工作正常!当我在我的应用程序的iOS模拟器中运行它时,UIView显示但不显示按钮。我不知道发生了什么事。UIButton不显示UIView使用Swift
var ySize = UIScreen.mainScreen().bounds.size.height - 40
let searchView = UIView(frame: CGRect(x: 0, y: ySize, width: self.view.bounds.width, height: 40))
searchView.backgroundColor = UIColor(red: 0/255.0, green: 71/255.0, blue: 133/255.0, alpha: 1)
let searchButton: UIButton = UIButton.buttonWithType(.System) as UIButton
searchButton.frame = searchView.frame
searchButton.tintColor = UIColor.whiteColor()
searchButton.setTitle("Search Transactions", forState: .Normal)
searchView.addSubview(searchButton)
self.navigationController?.view.addSubview(searchView)
尝试用'searchButton'的'center'财产玩耍和看。我的猜测是你的按钮不在屏幕上。 – Unheilig 2014-11-06 15:33:59
我只是累了,仍然没有运气。如果我添加一个UILabel它的作品。只是按钮不起作用。我感到很困惑! – lostAtSeaJoshua 2014-11-06 15:45:24