0
我有一個按鈕,我可以用這個代碼很容易找到:Swift3 - 無法找到UISegmentedControl編程
let btnRewind = UIButton(
frame:CGRect(
x:(UIScreen.main.bounds.size.height/2 - 4*UIScreen.main.bounds.size.height/30),
y:(UIScreen.main.bounds.size.width/2 - UIScreen.main.bounds.size.height/30),
width:(UIScreen.main.bounds.size.height/15),
height:(UIScreen.main.bounds.size.height/15)
)
)
但相同的代碼不適合我的工作UISegmentedControl。這就是x:0 y:0。我在想什麼:/
var sgmSpeed = UISegmentedControl(
frame:CGRect(
x:(UIScreen.main.bounds.size.height/2 - UIScreen.main.bounds.size.height/30),
y:(UIScreen.main.bounds.size.width/2 - UIScreen.main.bounds.size.height/30),
width:(UIScreen.main.bounds.size.height/15),
height:(UIScreen.main.bounds.size.width/15)
)
)
嘗試使用'initWithItems'構造。文檔稱「自動調整大小以適應其內容」。 –