的UISwitch我的设备上:Switch Image with the bottom pixels cut off http://gorgando.com/uiswitch.jpg底部被切断的设备上,但显示正常的模拟器
的UISwitch在模拟器上:Good UISwitch http://gorgando.com/uiswitch-good.png
正如你所看到的,底部像素在设备上切断,但不在模拟器上。我尝试过所有我能想到的事情,但没有解决问题。
一些我试过的东西:
- 更改UISwitch的框架的高度
- 改变UICell的高度
- 更改UICell的内容查看的高度
- 添加UISwitch到UICell而不是UICell的内容查看
以下是相关代码:
这是的UITableViewController的viewDidLoad中:
UISwitch *sw = [[UISwitch alloc] init];
self.contactedSwitch = sw;
[sw release];
self.contactedSwitch = [UISwitch switchWithLeftText:@"YES" andRight:@"NO"];
self.contactedSwitch.center = CGPointMake(230, 22);
self.contactedSwitch.on = [self.contact.contacted boolValue];
这就是switchWithLeftText:andRight方法来源于:
#import "UISwitch-Extended.h"
#define TAG_OFFSET 900
@implementation UISwitch (tagged)
- (void) spelunkAndTag: (UIView *) aView withCount:(int *) count
{
for (UIView *subview in [aView subviews])
{
if ([subview isKindOfClass:[UILabel class]])
{
*count += 1;
[subview setTag:(TAG_OFFSET + *count)];
}
else
[self spelunkAndTag:subview withCount:count];
}
}
- (UILabel *) label1
{
return (UILabel *) [self viewWithTag:TAG_OFFSET + 1];
}
- (UILabel *) label2
{
return (UILabel *) [self viewWithTag:TAG_OFFSET + 2];
}
+ (UISwitch *) switchWithLeftText: (NSString *) tag1 andRight: (NSString *) tag2
{
UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 94, 27)];
int labelCount = 0;
[switchView spelunkAndTag:switchView withCount:&labelCount];
if (labelCount == 2)
{
[switchView.label1 setText:tag1];
[switchView.label2 setText:tag2];
}
return [switchView autorelease];
}
@end
这是我的UISwitch添加到我的tableviewcell:
[[contactedCell contentView] addSubview:self.contactedSwitch];
非常感谢!
[更新]我认为tableviewcell的可能是问题,所以我将这些UISwitches添加到常规的UIView中,以查看它们的外观。我有完全相同的问题,他们在模拟器中看起来没问题,底部在设备中被切碎。太奇怪了!
您不能更改UISwitch的默认大小,因为它只会忽略您的代码。您可以尝试增加单元格大小并将其从边缘移开。如果仔细观察,看起来顶部会被模拟器截断,底部会被夹在设备上。所以无论哪种方式它都会被裁剪掉。 – iwasrobbed 2010-06-24 19:36:00
我只是将开关添加到常规的UIView并得到相同的结果。它们在模拟器中看起来不错,但底部仍然在设备上被切断。我猜这消除了UITableViewCell不够大,因为这些UISwitch在它们周围都有足够的空间。 – Brad 2010-06-24 20:58:46