Search code examples
iosuser-interfaceuikitiboutlet

How to customize a ui item, and apply that to all viewcontrollers?


I have a UITextField, that I had customized in my firstViewController. Now I wan't it to have the same behavior on the other ViewControllers. Is there anyway to import all the properties on a IBOutlet?


Solution

  • simple create your own Customclass and set the property in the constructor.

    @interface CustomTextField : UITextField
    
    @end
    
    
    @implementation CustomTextField
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
          //Customize here
          self.autocapitalizationType = UITextAutocorrectionTypeDefault;
          self.text = @"Blub";
          ....
        }
        return self;
    }
    @end
    

    if your create a new Textfield, create the object with your custom class:

    CustomTextField *field = [[CustomTextField alloc] initWithFrame: ...];