【问题标题】:Can not change the frame of an IBOutlet property无法更改 IBOutlet 属性的框架
【发布时间】:2014-10-13 06:08:41
【问题描述】:

说,我有一个 ViewController 并设置了一个属性:

@property (nonatomic, strong) IBOutlet UIView *contentView;

在Controller的xib文件中,我在默认的UIView上添加了一个UIView,并将其frame设置为{0, 0, 320, 568}。我将它与属性 contentView 连接起来。

在 viewDidLoad 方法中我这样做:

- (void)viewDidLoad {
    [super viewDidLoad];
    contentView.frame = CGRectMake(0, 20, 320, 300);
    contentView.backgroundColor = [UIColor purpleColor];   //frame print to be {0, 20, 320, 300}
}

问题是 contentView 的框架在 iphone 上呈现为 {0, 0, 320, 568}。但是我打印出框架,使其成为我在 viewDidLoad 方法中设置的内容。

这是怎么发生的?谢谢~

【问题讨论】:

    标签: ios objective-c xib


    【解决方案1】:

    你在使用自动布局吗?

    如果是,则不能更改框架。

    要么关闭自动布局,要么使用约束来更改视图的大小。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-03-08
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多