1

以下のコードがあります。しかし、ビューに UIButton が表示されません。ヘルプ!

UIButton *addTag = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[_overlayView addSubview: addTag];

[_overlayView setTranslatesAutoresizingMaskIntoConstraints:NO];


[_overlayView addConstraint:[NSLayoutConstraint constraintWithItem:_overlayView
                             attribute:NSLayoutAttributeCenterX
                             relatedBy:NSLayoutRelationEqual
                                toItem:addTag
                             attribute:NSLayoutAttributeCenterX
                            multiplier:1
                              constant:0]];

[_overlayView addConstraint: [NSLayoutConstraint constraintWithItem: _overlayView
                             attribute: NSLayoutAttributeBottom
                             relatedBy: NSLayoutRelationGreaterThanOrEqual
                                toItem:addTag
                             attribute:NSLayoutAttributeBottom
                            multiplier:1
                              constant:20]];

[addTag setTitle:@"Add Tag" forState:UIControlStateNormal];

高さと幅を指定する必要がありますか? これを自動的に設定する方法はありませんか。

[addTag sizeToFit] を追加すると、左上隅にボタンが表示されます。

4

1 に答える 1