gpt4 book ai didi

ios - 以编程方式在 FBLikeControl 上添加约束

转载 作者:行者123 更新时间:2023-11-29 02:10:17 24 4
gpt4 key购买 nike

如何以编程方式在 FBLikeControl 之类的 View 上添加约束?

我想在我的 View 中为 CGRect 添加恰到好处的边距:self.view,里面有 FBLikeControl

这是我的代码:

FBLikeControl *fbLikeControlView = [[FBLikeControl alloc] initWithFrame:CGRectMake(240, 20, 165, 30)];
fbLikeControlView.likeControlStyle = FBLikeControlStyleBoxCount;
[self.view addSubview:fbLikeControlView];
// [NSLayoutConstraint constraintWithItem:fbLikeControlView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:20.0];

我已经测试了一个带有属性 attribute:NSLayoutAttributeHeight 的 NSLayoutConstraint,它不会崩溃,但是如果我写 NSLayoutAttributeRightMargin 会崩溃......

我不知道怎么做,也找不到好的教程:/

最佳答案

如果您使用自动布局来放置 FBLikeControl,则需要添加足够的约束以明确放置它。您只是添加了一个高度限制。您还需要添加水平约束和垂直偏移约束。

您还需要调用[fbLikeControlView setTranslatesAutoresizingMaskIntoConstraints:NO]

如果您可以提供有关如何布局它的更多详细信息,我可以帮助您处理约束。

关于ios - 以编程方式在 FBLikeControl 上添加约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29349375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com