Up until now, I was able to avoid using Auto Layout, so apologies for the (potentially) stupid question.
addSubview:
)Here's some sample code I have that is creating the UIPageControl and displaying it, but not in the correct location at all.
self.pageControl = [[UIPageControl alloc] init];
self.pageControl.numberOfPages = ...;
self.pageControl.otherAttributes = ...;
[self.view addSubview:[self pageControl]];
UIPageControl *pageControl = [self pageControl];
UIView *view = [self view];
NSDictionary *constaintDictionary = NSDictionaryOfVariableBindings(view, pageControl);
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:pageControl
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[pageControl]-20-[view]"
options:0
metrics:nil
views:constaintDictionary]];
Like I said, I'm really new to auto-layout, so I'm not sure if I'm even implementing these methods properly.
Thank you for your assistance ahead of time.
Alright, I figured out how to do it. Took an inordinate amount fo time, but after i read through the Visual Format Language docs again, I came up with this:
UIPageControl *pageControl = [self pageControl];
[pageControl setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-0-[pageControl]-0-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(pageControl)]];
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[pageControl]-40-|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(pageControl)]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With