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

前端 未结 2 1904
伪装坚强ぢ
伪装坚强ぢ 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

提交回复
热议问题