【发布时间】:2014-11-06 15:25:13
【问题描述】:
我正在尝试创建一个位于屏幕底部的视图。 UIView 正常工作并显示。我试图在其中放置一个 UIView 大小的 UIButton,但该按钮不会显示。我把这段代码放在了 Swift Playground 中,它成功了!当我在我的应用程序的 iOS 模拟器中运行它时,UIView 显示但不显示按钮。我不知道发生了什么。
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属性看看。我猜你的按钮不在屏幕上。 -
我只是累了,还是没有运气。如果我添加一个 UILabel 它可以工作。只是按钮不起作用。我很困惑!
标签: iphone xcode swift uibutton ios8