UIVIew
其中的约束条件将其布局为与顶部、左侧和右侧屏幕以及底部按钮相同的大小:
然后从
ViewController
UIButtons
这样地:
override func viewDidLoad() {
super.viewDidLoad()
drawCards()
}
private func drawCards(){
let deck = Deck()
var rowIndex = 0
var columnIndex = 0
let cardWidth = Int(Float((deckView.bounds.width) / 7))
let cardHeight = Int(Float(cardWidth) * 1.5)
for card in deck.cards{
let x = (cardWidth / 2) * columnIndex
let y = cardHeight * rowIndex
let button = CardButton()
button.delegate = self
button.setCard(card: card, x: x, y: y, width: cardWidth, height: cardHeight)
deckView.addSubview(button)
columnIndex += 1
if(columnIndex == 13){
columnIndex = 0
rowIndex += 1
}
}
}
预期的行为是,此函数应采用
UIView
(称为
deckView
UIButtons
并且相互堆叠,并且在设备之间具有一致的布局。然而,它在iPhone上看起来和预期的一样,但在iPad上却不像预期的那样
UIButtons
走出国门
:
就我所知,这是因为
X
和
Y
UIView
(
为什么这条路不宽
是否按预期检索?