8
8

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.

UIButtonにsetImageしたときもAspectFitできる。

8
Posted at

UIButtonにsetImageしたときも、UIImageViewと同様にAspectをコードで変更できます。

//Button作成
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,44,44);

//UIImageの作成
UIImage *image = [UIImage imageNamed:@"ABCimage.png"];

//Buttonにimage貼り付け
[button setImage:image forState:UIControlStateNormal];

//Aspect変更
button.imageView.contentMode = UIViewContentModeScaleAspectFit;

以上です。

8
8
0

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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?