小编Swi*_*ft2的帖子

iOS 9 UIButton初始化

我试图以UIButton编程方式初始化,但看到以下错误之一:

buttonWithType不可用:使用对象构造UIButton(类型:)

要么

错误:调用中的参数标签不正确(有'buttonWithType:',期望'类型:')

  for char in keys {
        let btn: UIButton = UIButton.buttonWithType(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.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)
    }
Run Code Online (Sandbox Code Playgroud)

错误

uibutton ios swift ios9

11
推荐指数
1
解决办法
1万
查看次数

UIButton没有名为setTranslatesAutoresizingMaskIntoConstraints的成员

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

UIButton没有名为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)
    }
Run Code Online (Sandbox Code Playgroud)

ios swift

0
推荐指数
1
解决办法
2298
查看次数

标签 统计

ios ×2

swift ×2

ios9 ×1

uibutton ×1