2016-05-05 6 views
1

私はストーリーボードを使わずにアプリを作ろうとしていますが、問題があります。私はカスタムセルを設定して、すべてがiPhone 5SでOKになります : enter image description hereカスタムテーブルのUILabelの位置表示セル

しかし、私の右のラベルが上間違って見えますが、例えば、iPhoneの6S +: enter image description here

ここでは私のコードです:

class CustomTableViewCell: UITableViewCell { 


var leftLabel = UILabel() 
var currencyValueLabel = UILabel() 



required init?(coder aDecoder: NSCoder) { 
    super.init(coder: aDecoder) 
} 


override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
    super.init(style: style, reuseIdentifier: reuseIdentifier) 

    leftLabel = UILabel(frame: CGRect(
      x: 16, 
      y: 8, 
      width: 100, 
      height: self.bounds.size.height-16 
     )) 
     leftLabel.textAlignment = .Left 
     addSubview(leftLabel) 

    currencyValueLabel = UILabel(frame: CGRect(
      x: self.bounds.size.width-116, 
      y: 8, 
      width: 100, 
      height: self.bounds.size.height-16 
     )) 
     rightLabel.textAlignment = .Right 
     addSubview(rightLabel) 

} 


} 

更新: 私は、自動レイアウト試してみた:

leftLabel.leadingAnchor.constraintEqualToAnchor(self.layoutMarginsGuide.leadingAnchor, constant: 20).active = true 
    leftLabel.centerYAnchor.constraintEqualToAnchor(self.layoutMarginsGuide.centerYAnchor).active = true 

、これは私が一定の設定で間違っている、しかし、何かがわからないことを知っている

2016-05-05 18:49:09.849 RubApp[57636:2228350] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
     (1) look at each constraint and try to figure out which you don't expect; 
     (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503d21c50 h=--& v=--& UILabel:0x7fc503cea100'EUR'.midX == + 66>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503d1ea40 h=--& v=--& H:[UILabel:0x7fc503cea100'EUR'(100)]>", 
    "<NSLayoutConstraint:0x7fc503ce7c00 UILabel:0x7fc503cea100'EUR'.leading == UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'.leading + 20>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503ce98e0 h=-&- v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[RubApp.MainViewCell:0x7fc505868000'idTableCellMainView'] (Names: '|':UITableViewWrapperView:0x7fc505869600)>", 
    "<NSLayoutConstraint:0x7fc503ce7df0 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'](LTR) (Names: '|':RubApp.MainViewCell:0x7fc505868000'idTableCellMainView')>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fc503ce7c00 UILabel:0x7fc503cea100'EUR'.leading == UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'.leading + 20> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
2016-05-05 18:49:09.857 RubApp[57636:2228350] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
     (1) look at each constraint and try to figure out which you don't expect; 
     (2) find the code that added the unwanted constraint or constraints and fix it. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503e5a720 h=--& v=--& UILabel:0x7fc503e49b50'USD'.midX == + 66>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503e5a940 h=--& v=--& H:[UILabel:0x7fc503e49b50'USD'(100)]>", 
    "<NSLayoutConstraint:0x7fc503e56f50 UILabel:0x7fc503e49b50'USD'.leading == UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'.leading + 20>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7fc503e5ab70 h=-&- v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[RubApp.MainViewCell:0x7fc504030a00'idTableCellMainView'] (Names: '|':UITableViewWrapperView:0x7fc505869600)>", 
    "<NSLayoutConstraint:0x7fc503e4a780 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'](LTR) (Names: '|':RubApp.MainViewCell:0x7fc504030a00'idTableCellMainView')>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fc503e56f50 UILabel:0x7fc503e49b50'USD'.leading == UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'.leading + 20> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

結果です。申し訳ありませんが、この質問がばかだが、これはストーリーボードのない最初のアプリです。

+2

ので、あなたは、自動レイアウトを使用していない理由はありますか? – Wain

+0

FYI - タイプミスがあります(そのため、コードをコピーして貼り付ける必要があります)。 'currencyValueLabel'を作成しますが、' rightLabel'として参照します。 – rmaddy

+0

@Wain質問を更新しました。あなたは自動レイアウトで私を助けることができますか? – dsk1306

答えて

3

1つのオプションは、ちょうど​​前にこの行を追加することです:

rightLabel.autoresizingMask = .FlexibleLeftMargin 
+0

助けてくれてありがとう。 – dsk1306

0

あなたはxの末尾に制約を持つように右側のラベルを伝えるNSLayoutConstraintを追加する必要があります。

+0

私は自分の質問を更新しました。あなたは自動レイアウトで私を助けることができますか? – dsk1306

+0

私は質問が回答されているとして、あなたは、もはや、これを必要としないと仮定していますが、私はあなたに正しいコードを表示したい場合は、それは私の喜びになります。 –

関連する問題