【问题标题】:Rotated UIPicker displaying labels low-res?旋转 UIPicker 显示标签低分辨率?
【发布时间】:2011-04-09 02:07:38
【问题描述】:

我一直在研究一个水平的 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]];

  }

【问题讨论】:

    标签: iphone xcode ios4 ios uipickerview


    【解决方案1】:

    我发现了这个问题,所以我想我会在这里发布答案。现在很明显了。我在文本上使用与 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多