我想在我的 UITextFields 底部有一个两行 UILabel,作为免责声明。
我有以下代码viewDidLoad
:
UILabel *InstapaperSubscriptionLabel = [[UILabel alloc] init];
InstapaperSubscriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;
InstapaperSubscriptionLabel.text = @"Requires an Instapaper subscription, please see the Instapaper website for more details.";
InstapaperSubscriptionLabel.numberOfLines = 2;
InstapaperSubscriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
InstapaperSubscriptionLabel.preferredMaxLayoutWidth = self.view.bounds.size.width - 40;
InstapaperSubscriptionLabel.textAlignment = NSTextAlignmentCenter;
InstapaperSubscriptionLabel.backgroundColor = [UIColor clearColor];
InstapaperSubscriptionLabel.textColor = [UIColor colorWithRed:112/255.0 green:112/255.0 blue:111/255.0 alpha:1.0];
InstapaperSubscriptionLabel.font = [UIFont systemFontOfSize:14.0];
[self.view addSubview:InstapaperSubscriptionLabel];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:InstapaperSubscriptionLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.passwordBox
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:15.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:InstapaperSubscriptionLabel
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:20.0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:InstapaperSubscriptionLabel
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:20.0]];
但每次我加载视图时,它看起来像这样:
它离开屏幕一侧的地方。为什么要这样做?我希望它更居中。