UIPickerView的变形文本

时间:2012-03-20 09:10:26

标签: objective-c xcode text uipickerview dimensions

我有一个UIPickerView我使用CGAffineTransformMakeScale方法调整了大小,但是内部pickerview的文本因转换而变形。我无法附上结果的截图,但为了做到这一点,我写了这段代码:

-(void)espandi
{
//    map.frame=CGRectMake(0, 0, 320, 297);
//    toolBar.frame=CGRectMake(0, 297, 320, 22);
map.frame=CGRectMake(0, 0, 320, 351);
toolBar.frame=CGRectMake(0, 351, 320, 22);
//    piker.frame=CGRectMake(-10, 309, 340, 78);
piker.transform = CGAffineTransformMakeScale(1.07,0.45);
piker.frame=CGRectMake(-10, 363, piker.frame.size.width,piker.frame.size.height);

barBtn.image=[UIImage imageNamed:@"giu.png"];

//    lab1.frame=CGRectMake(28, 297, 42, 21);
//    lab2.frame=CGRectMake(128, 297, 42, 21);
//    lab3.frame=CGRectMake(233, 297, 42, 21);
lab1.frame=CGRectMake(28, 351, 42, 21);
lab2.frame=CGRectMake(128, 351, 42, 21);
lab3.frame=CGRectMake(233, 351, 42, 21);
[lab1 setHidden:NO];
[lab2 setHidden:NO];
[lab3 setHidden:NO];
}

-(void)contrai
{
map.frame=CGRectMake(0, 0, 320, 438);
toolBar.frame=CGRectMake(0, 438, 320, 22);

barBtn.image=[UIImage imageNamed:@"su.png"];

lab1.frame=CGRectMake(28, 438, 42, 21);
lab2.frame=CGRectMake(128, 438, 42, 21);
lab3.frame=CGRectMake(233, 438, 42, 21);
[lab1 setHidden:YES];
[lab2 setHidden:YES];
[lab3 setHidden:YES];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 3;
}


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *pickerLabel = (UILabel *)view;

if (pickerLabel == nil) {
    CGRect frame = CGRectMake(0.0, 0.0, 80, 60);
    pickerLabel = [[UILabel alloc] initWithFrame:frame];
    [pickerLabel setTextAlignment:UITextAlignmentCenter];
    [pickerLabel setBackgroundColor:[UIColor clearColor]];
    [pickerLabel setFont:[UIFont boldSystemFontOfSize:20]];
}

switch (component) {
    case 0:
        [pickerLabel setText:[tipo objectAtIndex:row]];
        break;

    case 1:
        [pickerLabel setText:[dist objectAtIndex:row]];
        break;

    case 2:
        [pickerLabel setText:@""];
        break;
}

return pickerLabel;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0){
    return [tipo count];
} else if (component == 1){
    return [dist count];
}
return 0; 
}

-(NSString *)pickerView:(UIPickerView *)thePickerview titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
switch (component) {
    case 0:
        return [tipo objectAtIndex:row];
        break;

    case 1:
        return [dist objectAtIndex:row];
        break;
}
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (component) {
    case 0:
        tipoSel=[tipo objectAtIndex:row];
        break;

    case 1:
        distSel=[dist objectAtIndex:row];
        break;
}
[self loadSpilli];
}

- (IBAction)upBtn:(id)sender
{
if (contr)
{
    //barra espansa bisogna ricontrolla - contract the tool bar
    [self contrai];
}
else
{
    //barra contratta bisogna espanderla - expand the tool bar
    [self espandi];
}
contr=!contr;
}

我该如何修复文字?或者我如何使控件尊重文本宽高比?

0 个答案:

没有答案