Chase Roberts
Chase Roberts

Reputation: 9376

Swapping UIViews for UIButtons in storyboard

I am guessing that this isn't possible. I spent about 2 hours laying out my views in autolayout. When I started coding, I realized that half of the views I laid out should actually be UIButtons. Is there anyway to just select a UIView and somehow change it to a UIButton? I tried typing in UIButtonto the class field. But it didn't change all the attributes like as if I had dropped a UIButton on the storyboard.

Upvotes: 6

Views: 968

Answers (1)

jbbenni
jbbenni

Reputation: 1178

You can open the Storyboard as source (right click on the Storyboard file and select Open As Source Code). Then use Find Menu's Find and Replace... to make changes. For example, change <view> to <button>. Save the file. After any desired text editing, right click on the Storyboard file again and Open As Interface Builder - Storyboard to restore the normal Storyboard view.

This is particularly useful when you want to change one color to another, or a to change a font name throughout a Storyboard. Just be careful, Storyboards can be rather fragile as text.

Upvotes: 4

Related Questions