Autolayout resize button based on text and have textfield fill available space

前端 未结 2 1900
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 18:17

I am working on an ios application using autolayout,

I have a UITextField and a UIButton next to it horizontally.

The UIButton text is changed dynamically. It ca

相关标签:
2条回答
  • 2021-02-04 18:26

    Try these autolayout constraints:

    23226220_Autolayout_Constraints


    Basically:

    1. UITextField object's width constraint should be a Less Than or Equal relation
    2. UIButton object's width constraint should be a Greater Than or Equal relation
    3. UITextField object's horizontal Content Hugging Priority should be 249 (as per my constraint settings shown above)

    And related code as:

    [buttonObject setTitle:@"Button title is too... zzz" forState:UIControlStateNormal];
    [buttonObject sizeToFit];
    

    ...or something along these lines

    0 讨论(0)
  • 2021-02-04 18:32

    increase button horizontal content hugging priority such that it is higher than the adjacent components' horizontal content hugging priority

    0 讨论(0)
提交回复
热议问题