Changing a UILable to UITextView with out removing and adding from the object library Changing a UILable to UITextView with out removing and adding from the object library xcode xcode

Changing a UILable to UITextView with out removing and adding from the object library


This is a significant annoyance with IB. If you change a view object in the identity inspector, it sort of works. The problem is that the properties of the object in IB are set up when it is first added. IB will continue to show the settings for the old type.

If you change a view to a different type, the properties shown in the Attributes inspector and the other tabs in IB don't change like they should.

If on the other hand you delete the previous object and add an instance of the new object type, your constraints, outlets, and actions are all lost.

I discovered the other day that if I selected a group of objects in IB and select "embed in view" then it removes all the constraints from the newly embedded objects. ARGGGH! I had a fairly complex set of views and controls and I had their layout and constraints all set up so they looked and resized correctly, and then I realized I needed them to be enclosed in a view. After selecting "embed in view" I was back at the beginning again, and probably wasted 15 or 20 minutes getting the constraints right again.


While I agree with the other answers regarding using caution when changing the XML directly, I have found the need to make a similar change, and have done so, keeping my constraints intact and have been successful.

Make sure you are using source control so that you can abandon your changes if needed.

I suggest making the properties of your modified control match a working control of the new type created in interface builder.

Example

To change from Label to Text Field, you would change the "label" tag in the XML to "textField."

<label opaque="NO" ... </label>

becomes

<textField opaque:NO ... </textField>

where "..." is the rest of the attributes and elements of the control.

Once the element tag change is completed, modify the attributes of the element to match a textField (in this case) to another Text Field created in interface builder. Be careful that the id attribute is not changed; the id attribute is how your constraints are mapped to the control.

Save the file and then reopen the file in interface builder. If interface builder can parse the file, then you can resume development as normal.

Again, use caution, but this can be a big time saver.


Edit the storyboard as plain xml is a very bad idea. If you want text view instead of UILabel is because you expect different behavior for each one, so I think the best solution is to remove and start again with text views.