How can I dynamically hide a button from a view?

前端 未结 12 2114
执念已碎
执念已碎 2020-12-04 21:24

I would like to dynamically hide a button in one of my views depending on a certain condition.

I tried adding some code to the view controller\'s -viewWillAppe

12条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 22:10

    This is a bit of a hack, but it works in my case (and it properly handles dynamic spacing):

    To hide:

    myButton.width = 0.1;
    

    To show:

    myButton.width = 0.0;
    

    A width of 0.0 is "auto width", and with a width of 0.1, the button totally disappears (not even a "sliver" of a button, though I haven't tried this on a retina display).

提交回复
热议问题