私のデバイスの UISwitch: 下のピクセルが切り取られたスイッチ画像 http://gorgando.com/uiswitch.jpg
シミュレーターの UISwitch: 良い UISwitch http://gorgando.com/uiswitch-good.png
ご覧のとおり、デバイスでは下のピクセルが切り取られていますが、シミュレータでは切り取られていません。考えられることはすべて試しましたが、問題は解決しませんでした。
私が試したことのいくつか:
- UISwitch のフレームの高さを変更する
- UICell の高さの変更
- UICell の contentView の高さを変更する
- UICell の contentView ではなく、UICell に UISwitch を追加する
関連するコードは次のとおりです。
これは、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 に追加して、それらがどのように見えるかを確認しました。シミュレーターで問題なく表示され、デバイスで底が切り刻まれるというまったく同じ問題があります。とても奇妙です!