2013-06-29 1 views
-2

У меня есть следующий код:Попытка добавить UIButton к моему виду с помощью Auto Layout, но это не отображается. Зачем?

- (void)addLogoutButton { 
    UIButton *logoutButton = [[UIButton alloc] init]; 
    logoutButton.translatesAutoresizingMaskIntoConstraints = NO; 
    [logoutButton setTitle:@"Logout" forState:UIControlStateNormal]; 
    [self.view addSubview:logoutButton]; 

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:logoutButton 
               attribute:NSLayoutAttributeTop 
               relatedBy:NSLayoutRelationEqual 
               toItem:self.view 
               attribute:NSLayoutAttributeTop 
               multiplier:1.0 
               constant:-100.0]]; 

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:logoutButton 
               attribute:NSLayoutAttributeLeft 
               relatedBy:NSLayoutRelationEqual 
               toItem:self.view 
               attribute:NSLayoutAttributeLeft 
               multiplier:1.0 
               constant:40.0]]; 


    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:logoutButton 
               attribute:NSLayoutAttributeRight 
               relatedBy:NSLayoutRelationEqual 
               toItem:self.view 
               attribute:NSLayoutAttributeRight 
               multiplier:1.0 
               constant:-40]]; 
} 

Но когда я запускаю приложение, кнопка нигде не найти. Почему это?

ответ

1

Изменит первые ограничения на постоянные +100.0 и инициализировать свою кнопку с:

[UIButton buttonWithType:UIButtonTypeRoundedRect]; 

 Смежные вопросы

  • Нет связанных вопросов^_^