Evgeniy Kleban
Evgeniy Kleban

Reputation: 6965

issue with programmatically added constraits

i use Masonry library to programmatically add constraints. Basically i simple add constrants from my button bot -> bottom of view (equal to 20 points) and from my button top -> bottom of label (equal 20). However, even when constraints values are equal, you can easily see that space from button to bot is lesser then space from button to top (meaning buttom -> top text). Here is code for set constraints:

[self.readNextButton mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.equalTo(self.containerForNewsText.mas_right).with.offset(-20);
        make.bottom.equalTo(self.containerForNewsText.mas_bottom).with.offset(-20);
        make.top.equalTo(self.truncatedNewsText.mas_bottom).with.offset(20);

    }];

enter image description here

Why is that happen? Maybe there is some feature involving button frame? Im not sure if that needed, but there is button created code:

    self.readNextButton = [UIButton new];
    self.readNextButton.titleLabel.adjustsFontSizeToFitWidth  = YES;
    self.readNextButton.backgroundColor = [UIColor whiteColor];
    [self.readNextButton setTitleColor:[UIColor colorWithHexString:@"#60aabf"] forState:UIControlStateNormal];
    self.readNextButton.titleLabel.lineBreakMode = NSLineBreakByClipping;
    self.readNextButton.titleLabel.font = [UIFont fontWithName:@"Roman" size:14];
    [self.readNextButton setTitle:@"Читать дальше" forState:UIControlStateNormal];
    [self.view addSubview:self.readNextButton];

Upvotes: 1

Views: 58

Answers (1)

Tim007
Tim007

Reputation: 2557

self.readNextButton.backgroundColor = [UIColor blueColor];
self.yourTopContent.backgroundColor = [UIColor redColor];

I think your constraint works, just add/minus value to make it right. Set 2 views different color for easily editing.

Upvotes: 1

Related Questions