0

制約を使用するのは初めてなので、何か問題が発生したことに驚かされることはありませんが、自分が何をしたか、および/またはそれを修正する方法を理解できません。

frameこれがプロパティを使用する私のメソッドです。正常に動作し、テキストビューが表示されます。

-(void)displayFeedbackText {
    feedback = [[UITextView alloc] init];
    feedback.backgroundColor = [UIColor clearColor];
    feedback.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
    NSString *t = @"If you have any problems with the" + 16; //Longest line of text view + padding.
    float textWidth = [t sizeWithFont:[UIFont fontWithName:@"Helvetica Neue" size:14]].width;
    float textHeight = [t sizeWithFont:[UIFont fontWithName:@"Helvetica Neue" size:14]].height;
    feedback.text=@"Thank you for buying My Haiku! \nIf you have any problems with the \napp, or if you want to share any \nthoughts or suggestions, please \nemail me at joel@xxxxx.com.";
    feedback.editable=NO;
    feedback.frame = CGRectMake(screenWidth/2-textWidth/2, (screenHeight/2-tabBarHeight) - (textHeight*6)/2, textWidth, textHeight*6);
    feedback.dataDetectorTypes=UIDataDetectorTypeAll;
    [self.view addSubview:feedback];
}

これが制約を使用する方法です(私はで設定self.view.translatesAutoresizingMaskIntoConstraintsNOましたviewDidLoad)。何も表示されません:

-(void)displayFeedbackText {
    feedback = [[UITextView alloc] init];
    feedback.backgroundColor = [UIColor clearColor];
    feedback.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
    feedback.text=@"Thank you for buying My Haiku! \nIf you have any problems with the \napp, or if you want to share any \nthoughts or suggestions, please \nemail me at joel@xxxxx.com.";
    feedback.editable=NO;
    feedback.dataDetectorTypes=UIDataDetectorTypeAll;
    NSLayoutConstraint *constraintX = [NSLayoutConstraint constraintWithItem:feedback attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    NSLayoutConstraint *constraintY = [NSLayoutConstraint constraintWithItem:feedback attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [self.view addConstraint:constraintX];
    [self.view addConstraint:constraintY];
    [self.view addSubview:feedback];
}

何が間違っているので、どうすれば修正できますか?

どうもありがとうございました。

4

1 に答える 1

1

サイズの制約がないため表示されていないと思うので、サイズはおそらくゼロです。明示的なサイズ制約またはスーパービューに関連する制約を設定してみてください。それらが明示的な制約である場合は、次のようにします (高さの制約も同様です)。

NSLayoutConstraint *widthCon = [NSLayoutConstraint constraintWithItem:feedback attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1  constant:320];
[feedback addConstraint:widthCon];
于 2013-01-16T18:21:34.887 に答える