2017-09-16 152 views

回答

-2

我知道更改元素的大小並使其保持相對的唯一方法到父容器的大小是使用(%)大小。

// index.html 
<body> 
    <div> 
     <a class="my-button" href="#">click me</a> 
     <a class="my-button" href="#">click me</a> 
     <a class="my-button" href="#">click me</a> 
     <a class="my-button" href="#">click me</a> 
     // .... more buttons 
    </div> 
</body> 

然後

// style.css 

.my-button { 
    width: 5%; 
} 
+1

但我使用的是swift –

0

我們可以使用自動佈局設置高度對於每個10個按鈕的具有相等的高度與上海華但與1:10

下面是一個乘法器顯示比例高度的示例截圖


enter image description here

0

我是通過在Stack中嵌入按鈕並將堆棧大小乘以屏幕大小的百分比來實現的,首先獲取屏幕大小。

let screenSize : CGRect = UIScreen.main.bounds 
let screenWidth = screenSize.width 
let screenHeight = screenSize.height 
buttonsStack.frame = CGRect(x: screenWidth * 0.75 , y: screenHeight * 0.3 , width: screenWidth * 0.27 , height: screenHeight * 0.67) 

X,Y是堆棧根據屏幕大小的位置。

相關問題