天天看點

UITextView設定占位文字placeHolder

// 通過runtime擷取UITextView所有的屬性和變量
//    unsigned int count = 0;
//    Ivar *ivarList = class_copyIvarList(objc_getClass("UITextView"), &count);
    UILabel *label = [UILabel new];;
    label.text = placeHolder;
    label.font = self.font;
    label.textColor = color == nil ? [UIColor lightGrayColor] : color;
    [self addSubview:label];
    // 通過KVC設定占位符
    [self setValue:label forKey:@"_placeholderLabel"];
           

Demo下載下傳位址