Reputation: 7888
I'm making this type of screen.
I've used 3 UIButton
and programmatically gave them border. The little red line is a UIView
. I've provided a constraint to UIView
Equal Widths as Trending Button.
Now my question that when user taps the next button this UIView
should move to the next one.
View Controller is 600x600
and next button is at 200x0
so if I change the value of UIView
to 200 that will be hard coded and it'll alter according to the screen size. I want it to be perfect and don't know any other way.
UPDATE:
I'm using AutoLayout
so for this purpose I used [self.buttonBottomView setTranslatesAutoresizingMaskIntoConstraints:YES];
and when I run the app the buttons were messed up like in the screenshot. I've applied some constraints
on buttons.
Upvotes: 2
Views: 89
Reputation: 1942
change frame of your UIView.
view.frame = CGRectMake(0+buttonWidth*i, y, width, height);
i is index which is 0 for Trending, 1 for Made by the fans and 2 for your rules.
Also when you change frame for your view, it is shown only on one button at a time.
Upvotes: 0
Reputation: 46
You can use NSLayoutConstraint
,change it's LeadingConstaint
when you tap on the next button.
Code:
- (void)changeSelectedByTapView:(UIView *)tapView {
_currentSelectedView = tapView;
self.lineImageViewLeadingConstaint.constant = tapView.frameX;
self.lineImageViewWidthConstaint.constant = tapView.width;
[UIView animateWithDuration:0.5f animations:^{
[self.lineImageView.superview layoutIfNeeded];
}];
}
Upvotes: 2