2017-08-08 8 views

答えて

1

あなたは、デバイスの種類(たとえば、iPadやiPhoneを)決定するためにあなたがhorizo​​ntalSizeClassを使用し、あなたがverticalSizeClassを使用する回転決定するため

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { 
super.willTransition(to: newCollection, with: coordinator) 
switch newCollection.verticalSizeClass { 
     case .compact: 
      yourLabel.textAligment = UITextAligment.left 
     case .regular, .unspecified: 
      yourLabel.textAligment = UITextAligment.center 
     } 
} 

でコンセントにこの動作を追加することができます。

+0

ですから、IBで行う方法はありません。ありがとう。 – Julien

+0

残念ながら、IBは、UI要素をコードで作成するよりも、UI要素を作成して操作する可能性があります。 –

0
if(width >= yourDesiredWidth){ 
    yourLabel.textAligment = UITextAligment.center 
} 
else{ 
    yourLabel.textAligment = UITextAligment.left 
} 
関連する問題