簡體   English   中英

無法更改從NIB加載的UIView中控件的屬性

[英]Cannot Change Properties of Controls inside an UIView that was Loadedfrom NIB

我不確定為什么會這樣。

在我的申請中,我有

  1. ViewController.swift
  2. CustomUIView.swift
  3. CustomUIView.xib

在我的ViewController.swift中

var customView: CustomUIView = NSBundle.mainBundle().loadNibNamed("CustomUIView", owner: self, options: nil).first as CustomUIView;
customView.setupControl();
self.view.addSubview(customView);

在我的CustomUIView.swift中,我嘗試更改在CustomUIView.XIB中創建的UIButton的屬性,例如這樣

@IBOutlet weak var button: UILabel!

 func setupControl()
 {
    label.frame = CGRect(x: 0 , y: 30, width: 320, height: 240); //THIS DOES NOT WORK

    label.text = "BLABLABLA"; //THIS WORKS
 }

我只能從InterfaceBuilder修改UIButton的屬性。

為什么會這樣呢?

您在使用自動版式嗎? 如果是,則無法設置框架,因為約束將覆蓋框架設置。 要更改框架,必須設置約束。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM