gpt4 book ai didi

ios - 为什么我的 UITextView 在使用框架属性时显示,但在使用约束时不显示?

转载 作者:行者123 更新时间:2023-11-29 04:11:21 25 4
gpt4 key购买 nike

我是使用约束的新手,所以我对出错并不感到惊讶,但我不知道我做了什么和/或如何修复它。

这是我使用 frame 属性的方法;它工作正常并且 TextView 显示:

-(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];
}

这是使用约束的方法(我已在 viewDidLoad 中将 self.view.translatesAutoresizingMaskIntoConstraints 设置为 NO)。没有显示任何内容:

-(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];
}

我做错了什么以及如何解决它?

非常感谢您的帮助。

最佳答案

我认为它没有显示出来是因为你没有大小限制,所以它的大小可能为零。尝试设置显式大小约束或相对于 super View 的大小约束。如果它们是显式约束,您可以这样做(并且与高度约束类似):

NSLayoutConstraint *widthCon = [NSLayoutConstraint constraintWithItem:feedback attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1  constant:320];
[feedback addConstraint:widthCon];

关于ios - 为什么我的 UITextView 在使用框架属性时显示,但在使用约束时不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14364916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com