Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ボタンのタイトルの位置を変えたいとき。おかしな現象を発見。
btn.titleLabel.center = CGPointMake(btn.titleLabel.center.x+10,btn.titleLabel.center.y);
この方法には問題があります!
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, a.origin.x +5,0,0)];
この方法いいですね!
クリックした後に最初の方法の効果が戻ってくるのはなぜですか!
おそらく、UIButton の実装が、エッジ インセットに基づいて titleLabel を配置するためです。そのため、位置を手動で設定できますが、インセットがそう言っているため、毎回リセットされます。
つまり、edgeInsets プロパティを使用して、UIButton に titleLabel を配置させます。