为什么我的UIButtons没有显示在我的容器内?

时间:2015-03-18 00:10:19

标签: ios objective-c swift

我有一个包含13 UIButton的视图。他们都使用自动布局。在这些按钮中有3个按钮就像容器一样,因为我想在它们上进行翻转过程,如果按下第13个按钮则显示不同的按钮。容器的布局很好。

所以在viewDidLoad中我创建了6个按钮。将3作为子视图添加到容器中(如果按下第13个按钮,则其他3个将被切换到3个第一个到UIView.transitionFromView。)

我创建按钮的代码如下:

func createCalculatorButton(title: String, frame: CGRect, color: UIColor, action: Selector) -> UIButton {
    var button = UIButton.buttonWithType(UIButtonType.System) as UIButton
    button.setTitle(title, forState: .Normal)
    button.frame = frame
    button.layer.borderWidth = 1
    button.setTranslatesAutoresizingMaskIntoConstraints(false)
    button.setBackgroundImage(GraphicHelper.imageBackground(color), forState: .Normal)

    button.addTarget(self, action: action, forControlEvents: .TouchUpInside)

    return button
}

使用的frame是每3个容器的框架。

当我运行应用程序时,它们不是放在容器中,而是放在手机左角的坐标(0.0,0.0)中(位于状态栏中)。

我不明白为什么当我通过addSubView在容器中添加按钮时,每个按钮的框架与其容器相同。

我的错误在哪里?

感谢您的帮助。

0 个答案:

没有答案