美文网首页
iOS14之后之后修改DatePicker 字体颜色

iOS14之后之后修改DatePicker 字体颜色

作者: petter102 | 来源:发表于2021-04-20 18:43 被阅读0次
unsigned int outCount;
    int i;
    objc_property_t *pProperty = class_copyPropertyList([UIDatePicker class], &outCount);
    for (i = outCount -1; i >= 0; i--)
    {
        // 循环获取属性的名字   property_getName函数返回一个属性的名称
        NSString *getPropertyName = [NSString stringWithCString:property_getName(pProperty[i]) encoding:NSUTF8StringEncoding];
        if([getPropertyName isEqualToString:@"textColor"])
        {
            [self.timePicker setValue:[UIColor whiteColor] forKey:@"textColor"];
        }
        
    }
    SEL selector = NSSelectorFromString(@"setHighlightsToday:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
    
    BOOL no = NO;
    [invocation setSelector:selector];
    [invocation setArgument:&no atIndex:2];
    [invocation invokeWithTarget:self.timePicker];

    self.timePicker.datePickerMode = UIDatePickerModeTime;  //真正想要展示的mode
    [self.timePicker setValue:[UIColor whiteColor] forKey:@"textColor"];

相关文章

网友评论

      本文标题:iOS14之后之后修改DatePicker 字体颜色

      本文链接:https://www.haomeiwen.com/subject/rnonlltx.html