簡體   English   中英

使用Swift在UIView中未顯示UIButton

[英]UIButton not showing in UIView using Swift

我試圖創建一個停留在屏幕底部的視圖。 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.frame = CGRectMake(0, 0, recentView.bounds.width, recentView.bounds.height)

迅捷3.x +

searchButton.frame = CGRect.init(x: 0.0, y:0.0, width:200.0, height:50.0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM