2017-02-14 9 views
1

テキストサイズやボタンは、iPhone 7とiPhone 6によさそうだが、iPhone 5SやiPhone上で動作しているとき、その大きさは同じまま5フォントサイズとUIViewのサイズは4Sは、iPhone 6とiPhone 5Sのために同じです

の場合私は15ポイントの左スペースの制約を与えるが、iPhone 7では本当に良いようだが、iPhone 5ではこれはあまりにも多くのスペースを与える。

すべてのファミリのデバイスでダイナミックビューとFontSizeを実装する方法。

ありがとうございます。

+0

前に試したこと、うまくいかなかったことを示すことができますか?参照[Ask] –

答えて

0

あなたはAutoLayoutを使用できます。あなたのビューをスーパービューの余白に制限するだけです。私。

yourView -> superView.Leading.Margin 
yourView -> superView.Trailing.Margin 

ビューコントローラの余白を使用することで、すべてのデバイスで正常に動作することを確認できます。

フォントサイズの場合、アップルではほとんどすべての状況で使用できる「prefferedFontStyles」というものを提供しています。だから、あなたはあなたのボタンだけで、すべてのデバイス上の通常の探してテキストサイズを持つようにしたい場合は、単純に次の操作を行います。取得するのに役立ちます

yourLabel.font = UIFont.preferredBody 

または

UIFont.preferredTitle 

などなど

・ホープそれを掛ける

0

たとえば、UIFont.systemFont(ofSize: 16)は、画面の幅が375ptの4.7インチのiPhoneではうまく見えますが、小さめのデバイスでは大きすぎると、フォントのベースを拡大することができますインセットの場合

let fontSize = UIScreen.main.bounds.width/375 * 16 
let font = UIFont.systemFont(ofSize: fontSize) 

...画面幅に編、@FlorensvonBuchwaldtごとに、それはスーパーの利益だと、あなたのUILabelを制約する自動レイアウトを使用し、その後、スケールされたインセットにlayoutMarginsを設定...

let margin = UIScreen.main.bounds.width/375 * 15 
myView.layoutMargins = UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin) 
0
// create global width ratio constant and use it when your need 
let _widthRatio : CGFloat = { 
    let ratio = _screenSize.width/375 
    return ratio 
}() 

//use constant 
let font = UIFont.systemFont(ofSize: fontSize * _widthRatio) 

// if you set font from storyboard then create subclass of your control 
class YMWidthLabel: UILabel { 
    override func awakeFromNib() { 
     super.awakeFromNib() 
     font = font.withSize(font.pointSize * _widthRatio) 
    } 
} 

// Now bind YMWidthLabel class in storyboard 
関連する問題