How can I dynamically hide a button from a view?

前端 未结 12 2148
执念已碎
执念已碎 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:21

    The best solution to this is less technical. All you need to do is create your normal navigation bar (top) or toolbar (bottom), but without the optional button. Then create another identical, but shorter bar which you then place at the part you want the optional button and create your optional button on this second shorter bar.

    Now you can call hidden = YES on the whole additional bar.

    The bars seamlessly overlap for me, your mileage may vary.

提交回复
热议问题