I'm creating a UISwitch in TableViewCell.
On retina display it looks fine.
But when I'm building a project on 3GS my UISwitch looks like a badly painted picture.
http://iwheelbuy.com/stackoverflow/asdf.png
My code
{
...
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;
}
First off, it would be easier in this case to just set the switch as the
accessoryViewof the cell and let it worry about the positioning.The reason you're seeing a blurry image is that your switch's frame has its origin on a half-pixel. You're setting the
centerof the switch, so where its origin is depends on the size of the switch (which is fixed, becauseUISwitchalways uses a system-defined size). So say the switch has a size of 79 x 27 (the standard size), setting the center's y-coordinate to 20 would cause the frame origin's y-coordinate to be at 6.5 (20.0 - 27.0 * 0.5).