Help us understand the problem. What is going on with this article?

iOS11でUIBarButtonItemのサイズがずれる

More than 1 year has passed since last update.

メンテナンスしていなかったアプリのUIBarButtonItemのサイズがやたらおかしくなっていたことに気づいた。

原因

UIBarButtonItemのレイアウト設定がautolayoutに対応したのが原因のよう

解決策

 let widthConstraint = button.widthAnchor.constraint(equalToConstant: 32)
 let heightConstraint = button.heightAnchor.constraint(equalToConstant: 32)
 heightConstraint.isActive = true
 widthConstraint.isActive = true
NSLayoutConstraint * widthConstraint = [customButton.widthAnchor constraintEqualToConstant:40];
NSLayoutConstraint * HeightConstraint =[customButton.heightAnchor constraintEqualToConstant:40];
[widthConstraint setActive:YES];
[HeightConstraint setActive:YES];

UIBarButtonItem* customBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customButton];
self.navigationItem.leftBarButtonItem = customBarButtonItem;

このように縦と横の制約を追加

kohei1218
主にiOS、たまにAndroid、Rails、ごくまれにLaravel
uzabase
企業活動の意思決定を支える情報インフラの提供
https://www.uzabase.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away