Slow load time for custom UIView with UITextView property in Swift

后端 未结 4 1394
一生所求
一生所求 2020-12-16 11:01

I originally asked this question. I had assumed that the reason for the slow load time of my custom view was because of layering multiple views on top of each other or perha

4条回答
  •  太阳男子
    2020-12-16 11:20

    Tried something similar where a label and a text field were added as a subviews to a uiview subclass. The way I did was the following:

    @interface CustomTextField : UIView
    
    @property (weak, nonatomic) IBOutlet UITextField *valueField;
    
    @end
    

    So, we had a xib file on which we actually add the label and the text field. On the xib file, the file owner is "CustomTextField" and outlets are linked with the header file from there.

    The constructor method looks like this:

    - (id)initWithValue:(NSString *)value
    {
        self = [super initWithFrame:CGRectZero];
        if (self) {
            NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
            UIView *view = nibs[0];
            self.valueField.frame = view.bounds;
            [self setFrame:view.bounds];
            [self addSubview:view];
            [self.valueField setText:value];
        }
    
        return self;
    }
    

    Works fine for me.

提交回复
热议问题