ios - 无法应用 addConstraints :NSLayoutConstraint to self. 窗口
<p><p>我正在尝试为状态栏添加背景。</p>
<p>当我尝试将 VFL 约束添加到 self.window 时,我收到错误 <strong>unexpected interface name: 'NSLayoutConstratint'</strong></p>
<pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIScreen *screen=[init];
UIWindow *window = [ initWithFrame:[ bounds]];
self.window.makeKeyAndVisible;
application.statusBarStyle = UIStatusBarStyleLightContent;
UIView *statusBarBackgroundView = [init];
statusBarBackgroundView.backgroundColor = ;
;
// Error while adding constraint below
[self.window addConstraints:NSLayoutConstraint
constraintsWithVisualFormat:@"H:||"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(statusBarBackgroundView)];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>最后一行缺少方括号:</p>
<pre><code> [self.window addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:||"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(statusBarBackgroundView)]];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 无法应用 addConstraints :NSLayoutConstraint to self. 窗口,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46030913/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46030913/
</a>
</p>
页:
[1]