2015-07-13 39 views
1

我將UIProgressView放在XIB文件上。起初它進展順利。當我通過自動佈局設置高度爲20時,出現了問題。進度視圖總是在屏幕的最左上角獲得它的位置。即使我用UIProgressView在運行時有不同的位置

[self.progress setFrame:CGRectMake(93, 100, self.scrollView.frame.size.width, self.scrollView.frame.size.height)]; 

仍然不適合我。

非常感謝您的幫助。

+0

使用自動佈局時不設置框架,請改用約束 – azimov

回答

0

使用尺寸約束作爲出口。然後,您可以輕鬆更改這些約束的值。當使用自動佈局時,不建議修改框架。

聲明屬性:

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint; 
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint; 

,並在執行:

self.heightConstraint = self.scrollView.frame.size.height; 
self.widthConstraint= self.scrollView.frame.size.width; 

另外,您可以嘗試在viewDidLayoutSubviews設置框架,但使用自動佈局時,不推薦。

+1

解決!我試圖在viewDidLayoutSubViews中做到這一點,它的工作。 –

相關問題