问题
I want to change font size of date picker and picker view. is this possible ? if is it? then how it done.
回答1:
There is no any API for change apperiance of UIDatePicker
.
You can make a pretty convincing replica yourself using a UIPickerView
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return a;}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return b;}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *lblpkr= [[UILabel alloc] initWithFrame:CGRectMake(p,q,r,s)];
[lblpkr setBackgroundColor:[UIColor clearColor]];
[lblpkr setTextColor:[UIColor blueColor]];
[lblpkr setFont:[UIFont boldSystemFontOfSize:x]];
[lblpkr setText:[NSString stringWithFormat:@"%d",row]];
return lblpkr;}
For Swift
See this for customizable implementation of UIDatePicker
https://github.com/prolificinteractive/PIDatePicker
回答2:
No you can't customise UIDatepicker
, as per given on apple's Official site.
So Developer has no rights to change UIDatepicker.
回答3:
Actually you can update the font size using method swizzling. This is how I change the font
#import "UILabel+Extra.h"
@implementation UILabel (Extra)
-(void)layoutSubviews{
[super layoutSubviews];
NSArray *arrayFont = [self.font.fontName componentsSeparatedByString:@"-"];
NSArray *arrayRobotoStyleName = [UIFont fontNamesForFamilyName:@"Roboto"];
__block NSString *style;
if(arrayFont.count >= 2){
[arrayRobotoStyleName enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop){
NSString *styleName = [arrayFont lastObject];
if ([obj containsString:styleName]){
style = styleName;
*stop = TRUE;
}
else if (index == ([arrayRobotoStyleName count] - 1)){
style = @"Regular";
*stop = TRUE;
}
}];
}
else
style = @"Regular";
if (!style) {
style = @"Regular";
}
self.font = [UIFont fontWithName:[NSString stringWithFormat:@"Roboto-%@",style] size:self.font.pointSize];
}
-(void)setAppearanceFont:(UIFont *)font{
if (font)
[self setFont:font];
}
-(UIFont *)appearanceFont{
return self.font;
}
来源:https://stackoverflow.com/questions/37678487/how-to-change-font-size-of-date-picker-view-and-picker-view-in-ios-objective-c