Note that there are some explanatory texts on larger screens.

plurals
  1. POIntrinsic size not updating when changing UIButton state
    primarykey
    data
    text
    <p>I have a UIView that contains a UIButton. The UIButton has 2 titles set for the UIControlStateNormal ("Follow") and UIControlStateSelected ("Following") states. I am using auto layout on the UIButton and it has a constraint to be a certain distance from the top of the superview and another to be a certain distance from the left side of the superview. I've also used "Size to fit Content" on it.</p> <p>When I set the button to be in the selected state from code, the title changes correctly but the intrinsic width of the UIButton doesn't change so that when changing from "Follow" to "Following" the text gets ellipsized.</p> <pre><code>self.selected = self.following; </code></pre> <p><img src="https://i.stack.imgur.com/gnAeU.png" alt="enter image description here"><img src="https://i.stack.imgur.com/6miWV.png" alt="enter image description here"></p> <p>When I approach the problem differently and simply change the text for UIControlStateNormal when someone hits the button, the button changes size correctly.</p> <pre><code>NSString *title = (self.following) ? @"Following" : @"Follow" [self setTitle:title forState:UIControlStateNormal]; </code></pre> <p><img src="https://i.stack.imgur.com/Jlmar.png" alt="enter image description here"><img src="https://i.stack.imgur.com/Vn0Xe.png" alt="enter image description here"></p> <p>Is this a bug in UIKit? I would expect the button to change its intrinsic size to correctly reflect the new size of the text when its state changes especially because there are other things I would like to change besides just the text for the 2 button states.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload