1

我有 UIDatePicker,我想在 UIDatePicker 中绘制时间,例如灰色

我需要这个,如果在我的图形中绘制了一些间隔,那么在 datePicker 中用户无法选择这个时间

在此处输入图像描述

4

2 回答 2

0

很抱歉告诉你,但UIDatePicker不支持像你描述的那样设置有效时间范围。唯一的选项是最小和最大日期。如果你真的需要这个,你需要从头开始构建一个自定义控件,这将花费很多精力。

于 2012-11-15T00:57:43.123 回答
0

I think I found my solution, I can draw time to another color

for (UIView *view in datePicker.subviews) {
        for (UIView *subView in view.subviews) {
            for (UIView *subSubView in subView.subviews) {
                for (UIView *thirdSubView in subSubView.subviews) {
                    for (UILabel *label in thirdSubView.subviews) {
                        if ([label isKindOfClass:[UILabel class]]) {
                            label.textColor = [UIColor redColor];
                        }
                    }
                }
            }
        }
    }

enter image description here

I need to catch event when scrolling DatePicker, I doing this, and this work, but I break the scroll

for (UIView *view in datePicker.subviews) {
        for (UIView *subView in view.subviews) {
            Class UIPickerTableView = objc_getClass("UIPickerTableView");

            if ([subView isKindOfClass:UIPickerTableView]) {
                UITableView *sub = (UITableView *) subView;
                sub.delegate = self;
            }
            for (UIView *subSubView in subView.subviews) {

enter image description here

I try doing another way, but it doesn't work

for (UIView *view in datePicker.subviews) {
        for (UIView *subView in view.subviews) {
            Class UIPickerTableView = objc_getClass("UIPickerTableView");

            Method targetMethod = class_getInstanceMethod(UIPickerTableView, @selector(scrollViewDidScroll:));
            Method newMethod = class_getInstanceMethod(UIPickerTableView, @selector(__scrollViewDidScroll:));
            method_exchangeImplementations(targetMethod, newMethod);

            for (UIView *subSubView in subView.subviews) {
于 2012-11-15T17:30:13.777 回答