146
138

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Autolayout時にUIViewのframeを変更する方法

Last updated at Posted at 2014-09-02

Autolayoutを使っていると、UIViewの大きさを変えたり、位置を変更したりができない。

imageview.frame = CGRectMake(0, 0, 100, 100);

これが効かない。

##AutoLayoutを解除する
特定のViewだけAutoLayoutを解除すると効くようになる。
translatesAutoresizingMaskIntoConstraintsを使う。

Swift 2.x系

//AutoLayout解除
imageview.translatesAutoresizingMaskIntoConstraints = true

//Viewのframe変更
imageview.frame = CGRectMake(0, 0, 100, 100);

swift 1.x系

//AutoLayout解除
imageView.setTranslatesAutoresizingMaskIntoConstraints(true)
//Viewのframe変更
imageview.frame = CGRectMake(0, 0, 100, 100);

objective-c

//AutoLayout解除
imageView.translatesAutoresizingMaskIntoConstraints = YES;
//Viewのframe変更
imageview.frame = CGRectMake(0, 0, 100, 100);

あまり多様するのはよくないけど、ちょっと変更したい時に。

146
138
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
146
138

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?