UIButton refactor for UILabel in storyboard

I have a view in my storyboard with lots of constrained UIButtons.

Is there a way to convert these buttons to labels without removing each button and creating a constrained shortcut?

+3


source to share


1 answer


  • The UIButton actually contains a UILabel to display its titleLabel. Thus, you can set the button's UserInteractionEnabled: property to NO.

  • UIButton can have border color. So set the border color as pure color.

  • Make UIButton a custom type.

    As you need to reconfigure constraints again, if you added labels, you can skip to the above solution.

Reason cannot change in IB / Storyboard:

You have dragged the UIButton from the library into your view. Even you try to change the class name to UILabel or its subclass, it won't change the class name.

because UILabel is just a UIView type, where UIButton is a UIControl type.



This is why you cannot change the UIButton class name for UILabel or UILabel subclass in IB.

Update:

No warranty / not recommended in Xcode release

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

+7


source







All Articles