search

Home  >  Q&A  >  body text

How to easily replace existing controls in iOS storyboard?

The wrong control type is used in an existing project:

How can we conveniently replace UITextField with UILabel without creating (drag) a new control.


ThanksChris for clearing up the confusion;
If there are many interfaces, you can specify the Label tag and search in the code to quickly locate the control.

巴扎黑巴扎黑2735 days ago1095

reply all(2)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-24 09:46:22

    Right click on xib or storyboard, Open As -> Source Code. Find the textField and change it to label. Then open it with interface builder. After modification, the original constraints and Frame will be retained.

    reply
    0
  • 为情所困

    为情所困2017-06-24 09:46:22

    Method 1:
    Write a class CustomTextField, inherit from UITextField, and then let all your UITextField controlsinherit it

    in the visual interface

    Disable all touch events in CustomTextField, which is basically consistent with the performance of UILabel
    If necessary, rewrite the system method of UITextField without calling the super method, for example, overwrite the click event of UIAlertView

    -(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated{
    //    [super dismissWithClickedButtonIndex:buttonIndex animated:animated];
        return;
    }
    

    Method 2:
    Add the category extension of UITextField, and then use the runtime method swizzling to exchange system methods, so that all your UITextField will become the same as UILabel. . . Use with caution! ! !

    Finally, if you have this spare time, it would be easier to delete and replace them one by one

    reply
    0
  • Cancelreply