Style all UITextFields at once rather than in each ViewController?

后端 未结 5 654
情深已故
情深已故 2021-01-03 00:45

I\'m trying to style all the textfields like so:

CGRect frameRect2 = _lastname_field.frame;
frameRect2.size.height = 30;

_lastname_field.font = [UIFont font         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 01:26

    Subclass UITextField and add your customization in the initWithFrame method. Add initWithCoder method in the custom class where you call the super and return [self initWithFrame:[self frame]]. Then change the class in Interface Builder for each text field.

    It will be something like this:

    // MyUITextField.h
    @interface MyUITextField : UITextField {
        // Your IVars
    }
    
    @property (retain, readonly) float value;
    @end
    
    // MyUITextField.m
    @implementation MyClass
    
    - (id)initWithCoder:(NSCoder *)decoder {
    
        [super initWithCoder:decoder];
        return [self initWithFrame:[self frame]];
    }
    
    - (id)initWithFrame:(CGRect)frame {
    
        self = [super initWithFrame:frame];
        if (self) {
            // Your customization
        }
    }
    
    @end
    

提交回复
热议问题