Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 非视网膜屏幕上的UI开关_Objective C_Ios_Uiswitch_Iphone 3gs - Fatal编程技术网

Objective c 非视网膜屏幕上的UI开关

Objective c 非视网膜屏幕上的UI开关,objective-c,ios,uiswitch,iphone-3gs,Objective C,Ios,Uiswitch,Iphone 3gs,我正在TableViewCell中创建UISwitch 在视网膜显示器上看起来很好 但当我在3GS上构建一个项目时,我的UISwitch看起来就像一幅画得不好的画 我的代码 { ... cell.textLabel.text = NSLocalizedString(@"settings model glare", nil); UISwitch *cellSwitch = [self switchWithTitle:@"glare"]; [cellSwitch se

我正在TableViewCell中创建UISwitch

在视网膜显示器上看起来很好

但当我在3GS上构建一个项目时,我的UISwitch看起来就像一幅画得不好的画

我的代码

{
    ...
    cell.textLabel.text = NSLocalizedString(@"settings model glare", nil);
    UISwitch *cellSwitch = [self switchWithTitle:@"glare"];
    [cellSwitch setCenter:CGPointMake(260.0f, cell.frame.size.height / 2)];
    [cell addSubview:cellSwitch];
    ...
}

- (UISwitch *) switchWithTitle:(NSString *)_title
{
    BOOL switchState;
    if ([[NSUserDefaults standardUserDefaults] boolForKey:_title] == NO)
    {
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:_title];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    switchState = [[NSUserDefaults standardUserDefaults] boolForKey:_title];
    UISwitch *switchForCell = [[UISwitch alloc] initWithFrame:CGRectZero];
    if ([_title isEqualToString:@"glare"])
        [switchForCell addTarget:self action:@selector(changedValueForGlare) forControlEvents:UIControlEventValueChanged];
    else
        [switchForCell addTarget:self action:@selector(changedValueForShadow) forControlEvents:UIControlEventValueChanged];
    [switchForCell setOn:switchState];
    return switchForCell;
}

不知道你说的画得不好是什么意思。它看起来模糊吗?这可能是因为其帧未设置为完整点

你的牢房有多高?以下行可能导致UISwitch被设置为点的0.5:

[cellSwitch setCenter:CGPointMake(260.0f, cell.frame.size.height / 2)];

这在视网膜上很好,因为它仍然是一个完整的像素,但在非视网膜上它是0.5个像素,因为点=非视网膜上的像素,点=视网膜上的2个像素。

不确定你所说的画得不好是什么意思。它看起来模糊吗?这可能是因为其帧未设置为完整点

你的牢房有多高?以下行可能导致UISwitch被设置为点的0.5:

[cellSwitch setCenter:CGPointMake(260.0f, cell.frame.size.height / 2)];

这在视网膜上很好,因为它仍然是一个完整的像素,但在非视网膜上它是0.5个像素,因为点=非视网膜上的像素,点=视网膜上的2个像素。

首先,在这种情况下,只需将开关设置为细胞的辅助视图,让它担心定位


您看到模糊图像的原因是交换机的帧的原点为半像素。您正在设置开关的中心,因此其原点的位置取决于固定的开关大小,因为UISwitch始终使用系统定义的大小。因此,假设开关的尺寸为79 x 27标准尺寸,将中心的y坐标设置为20将导致帧原点的y坐标为6.5 20.0-27.0*0.5。

首先,在这种情况下,只需将开关设置为单元格的附件视图,并让其担心定位问题,就更容易了


您看到模糊图像的原因是交换机的帧的原点为半像素。您正在设置开关的中心,因此其原点的位置取决于固定的开关大小,因为UISwitch始终使用系统定义的大小。因此,假设开关的尺寸为79 x 27标准尺寸,将中心的y坐标设置为20将导致帧原点的y坐标为6.5 20.0-27.0*0.5。

您可能需要上传问题的照片。很难说画得不好是什么意思。我上传了一张图片,你可能想上传一张关于这个问题的照片。很难说画得不好的图片是什么意思。我上传了一张图片。非常感谢您指出附件视图问题!这是一个很好的解决方案,非常感谢您指出附件视图问题!这是一个很好的解决方案,它肯定与像素偏移和错误的帧定位有关;我用半像素进行了测试。看起来好多了!它肯定与像素偏移和错误的帧定位有关;我用半像素进行了测试。看起来好多了!