How to easily replace existing controls in iOS storyboard?
巴扎黑
巴扎黑 2017-06-24 09:44:22
0
2
1071

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.

巴扎黑
巴扎黑

reply all(2)
淡淡烟草味

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.

为情所困

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template