gpt4 book ai didi

ios - UIButton 没有名为 setTranslatesAutoresizingMaskIntoConstraints 的成员

转载 作者:行者123 更新时间:2023-11-28 09:37:54 26 4
gpt4 key购买 nike

我正在使用 xcode 7 beta 2 并收到以下错误。我该如何解决?

UIButton does not have a member named setTranslatesAutoresizingMaskIntoConstraints

for char in keys {
let btn = UIButton(type: UIButtonType.System) as UIButton

btn.frame = CGRectMake(0, 0, 20, 20)
btn.setTitle(char, forState: .Normal)
btn.sizeToFit()
btn.titleLabel?.font = UIFont.systemFontOfSize(20)
btn.setTranslatesAutoresizingMaskIntoConstraints(false)
btn.backgroundColor = UIColor(hue: (216/360.0), saturation: 0.1, brightness: 0.81, alpha: 1)//
btn.setTitleColor(UIColor(white: 1.0, alpha: 1.0), forState: .Normal)

btn.setContentHuggingPriority(1000, forAxis: .Horizontal)
btn.setContentCompressionResistancePriority(1000, forAxis: .Horizontal)

btn.addTarget(self, action: Selector("handleBtnPress:"), forControlEvents: .TouchUpInside)

self.addSubview(btn)
}

最佳答案

translatesAutoresizingMaskIntoConstraints 是一个( bool )属性的 UIView。在 Objective-C 中,您可以使用“点语法”setter 方法为属性赋值

btn.translatesAutoresizingMaskIntoConstraints = NO;
[btn setTranslatesAutoresizingMaskIntoConstraints:NO];

但在 Swift 中,您只需为属性分配一个新值:

btn.translatesAutoresizingMaskIntoConstraints = false

关于ios - UIButton 没有名为 setTranslatesAutoresizingMaskIntoConstraints 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31252785/

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