I'm trying in my custom UITableViewCell
to get an equal space between all buttons.
What I get is all buttons have a huge width and height.
My goal is equal space and max size of 40x40 (only via code), but I don't know hot to do it.
My code so far:
- (void)addEqualSpaceToButtons
{
if (_didAddEqualSpace) {
return;
}
_didAddEqualSpace = YES;
// 1
self.btnCall.translatesAutoresizingMaskIntoConstraints = NO;
self.btnMessage.translatesAutoresizingMaskIntoConstraints = NO;
self.btnCalendar.translatesAutoresizingMaskIntoConstraints = NO;
self.btnMemo.translatesAutoresizingMaskIntoConstraints = NO;
self.btnForwardMessage.translatesAutoresizingMaskIntoConstraints = NO;
self.btnMore.translatesAutoresizingMaskIntoConstraints = NO;
self.btnDelete.translatesAutoresizingMaskIntoConstraints = NO;
// 2
NSLayoutConstraint *equalSpace = [NSLayoutConstraint constraintWithItem:self.btnDelete
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];
[self addConstraint:equalSpace];
// 3
NSDictionary *views = NSDictionaryOfVariableBindings(_btnDelete, _btnMore, _btnForwardMessage, _btnMemo, _btnCalendar, _btnMessage, _btnCall);
NSArray *fixEqualSpace = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_btnDelete][_btnMore(==_btnDelete)][_btnForwardMessage(==_btnDelete)][_btnMemo(==_btnDelete)][_btnCalendar(==_btnDelete)][_btnMessage(==_btnDelete)][_btnCall(==_btnDelete)]|"
options:NSLayoutFormatAlignAllBottom
metrics:nil
views:views];
[self addConstraints:fixEqualSpace];
}