2013-08-14 4 views
0

Мое ограничение VFL продолжает ломаться, и я не могу понять, почему. Это UIButton с настраиваемым фоном. Я хочу, чтобы он имел гибкую ширину, сохраняя при этом пространство в 10 пикселей с обеих сторон. Вот код:ios: ограничение моего vfl нарушено

- (void)viewDidLoad 
{ 
UIImage *buttonImage = [[UIImage imageNamed:@"bluebutton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)]; 
UIImage *buttonImageHighlight = [[UIImage imageNamed:@"bluebuttonHighlight.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)]; 
[[self view] addSubview:[self useLocationButton]]; 
[[self view] setTranslatesAutoresizingMaskIntoConstraints:NO]; 
NSDictionary *nameMap = @{@"locationbtn":[self useLocationButton],@"mainview":[self view]}; 
NSArray *horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[locationbtn(>=36)]-10-|" 
                     options:0 
                     metrics:nil 
                      views:nameMap]; 
[[self view] addConstraints:horizontalConstraints]; 
[[self useLocationButton] setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
[[self useLocationButton] setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted]; 
[[self useLocationButton] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[[self useLocationButton] setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; 

} 

ответ

0

Ответ был, что я поставил «setTranslatesAutoresizingMaskIntoConstraints» на родительский виде, а не кнопки. Эта строка должна быть следующей:

[[self useLocationButton] setTranslatesAutoresizingMaskIntoConstraints:NO]; 
Смежные вопросы