Malte
Malte

Reputation: 704

Replicating the UIDatePicker Font Style

i'm trying to replicate the exact font size used in UIDatePicker for a custom UIPickerView. Unfortunately I'm not able to get the correct font size.

What I've tried:

Swizzling the setFont: method of UILabel to print out the font when being a subclass of a UIDatePickerView

-(void) swizzledSetFont:(UIFont*)font{
    if([self view:self hasSuperviewOfClass:[UIDatePicker class]] ||
       [self view:self hasSuperviewOfClass:NSClassFromString(@"UIDatePickerWeekMonthDayView")] ||
       [self view:self hasSuperviewOfClass:NSClassFromString(@"UIDatePickerContentView")]){
       NSLog(@"Label:%@ Font:%@",self,font);
       [self swizzledSetFont:font];

    } else {
        //Carry on with the default
        [self swizzledSetFont:font];
    }
}

The same code works for swizzling the font color inside these labels, so thats not the problem.

This returns the following: <UICTFont: 0x7f9f23cea230> font-family: ".HelveticaNeueInterface-Regular"; font-weight: normal; font-style: normal; font-size: 21.00pt

But setting this as the font of UILabels inside the custom UIPickerView does not yield the desired look.

Any Ideas? I think there might be some kind of CALayer stuff going on here, but I'm out of ideas on how to debug this. It's iOS 8 btw.

Upvotes: 0

Views: 603

Answers (1)

Sandeep
Sandeep

Reputation: 21144

If your only purpose is just to know the font that UIDatePicker uses, using view debugger will simplify this lot more. Add a simple UIDatePicker to your view hierarchy and run it on your simulator. Then, debug the view and drill down the view hierarchy to find the font. I think this is lot more fun and simpler than what you have been doing.

enter image description here

Upvotes: 1

Related Questions