我一直在使用水平UIPicker,我终于得到了拾取器和拾取器上的标签,两者都显示为旋转。但是,我现在注意到的问题是标签显示在低分辨率和非常明显的像素化。使用字体值似乎对像素化没有影响。我已经包含了我的代码:
//在视图中加载了...
[super viewDidLoad];
myPicker.delegate = self;
myPicker.dataSource = self;
myPicker.showsSelectionIndicator =YES;
myPicker.backgroundColor = [UIColor blackColor];
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
//original settings
//rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
rotate = CGAffineTransformScale(rotate, 0.2, 1.65);
[self.myPicker setTransform:rotate];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"155", @"165", @"175",
@"185", @"195", @"205", @"215", nil];
self.pickerData = array;
[array release];
NSInteger TOTALITEM = [pickerData count];
UILabel *theview[TOTALITEM-1]; // + 1 for the nil
for (int i=1;i<=TOTALITEM-1;i++) {
theview[i] = [[UILabel alloc] init];
theview[i].text = [NSString stringWithFormat:@"%d",i];
theview[i].textColor = [UIColor blackColor];
theview[i].frame = CGRectMake(0,0, 25, 25);
theview[i].backgroundColor = [UIColor clearColor];
theview[i].textAlignment = UITextAlignmentCenter;
theview[i].shadowColor = [UIColor whiteColor];
theview[i].shadowOffset = CGSizeMake(-1,-1);
theview[i].adjustsFontSizeToFitWidth = NO;
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:10];
[theview[i] setFont:myFont];
}
CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-3.14/2);
rotateItem = CGAffineTransformScale(rotateItem, 1, 10);
for (int j=1;j<=TOTALITEM-1;j++) {
theview[j].transform = rotateItem;
}
pickerData = [[NSMutableArray alloc] init];
for (int j=1;j<=TOTALITEM-1;j++) {
[pickerData addObject:theview[j]];
}
答案 0 :(得分:0)
我发现了这个问题,所以我想我会在这里发布答案。现在很明显了。我在文本上使用与UIPicker相同的比例变换设置。为了解决这个问题,我将文本的变换减少了50%,并使用字体大小来控制标签的大小。这是我改变的代码:
原件:
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:10];
[theview[i] setFont:myFont];
}
CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-3.14/2);
rotateItem = CGAffineTransformScale(rotateItem, 1, 10);
修正:
UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:30];
[theview[i] setFont:myFont];
}
CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-3.14/2);
rotateItem = CGAffineTransformScale(rotateItem, .5, 5);