私の iPhone アプリにはセグメント化されたコントロールがあり、ios6 では問題なく動作しますが、ios7 ではセグメント タイルが切り捨てられます (テキスト用の十分なスペースがありますが、切り捨てられます)。
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
self.segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
NSDictionary *defaultTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:defaultFont,
UITextAttributeFont,
defaultFontColor,
UITextAttributeTextColor,
nil];
[self.segmentedControl setTitleTextAttributes:defaultTextAttributes forState:UIControlStateNormal];
NSDictionary *selectedTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:selectedFont,
UITextAttributeFont,
selectedFontColor,
UITextAttributeTextColor,
nil];
[self.segmentedControl setTitleTextAttributes:selectedTextAttributes forState:UIControlStateHighlighted];
これを修正する方法についての提案はありますか? ios6 では正しく動作するのに、ios7 ではタイトルが切り捨てられるのはなぜですか...
これは問題を引き起こすコードです...
UIImage *unselectedBackgroundImage = [[UIImage imageNamed:@"product_details_segmentBckg"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
/* Selected background */
UIImage *selectedBackgroundImage = [[UIImage imageNamed:@"product_details_segmentBckg"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
/* Image between two unselected segments */
UIImage *bothUnselectedImage = [[UIImage imageNamed:@"product_details_segmentBckg"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 0, 1, 0)];
/* Image between segment selected on the left and unselected on the right */
UIImage *leftSelectedImage = [[UIImage imageNamed:@"product_details_segmentBckg"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 0, 1, 0)];
/* Image between segment selected on the right and unselected on the right */
UIImage *rightSelectedImage = [[UIImage imageNamed:@"product_details_segmentBckg"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 0, 1, 0)];
if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
#ifdef __IPHONE_7_0
unselectedBackgroundImage = [unselectedBackgroundImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
selectedBackgroundImage = [selectedBackgroundImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
bothUnselectedImage = [bothUnselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
leftSelectedImage = [leftSelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
rightSelectedImage = [rightSelectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
#endif
}
[[UISegmentedControl appearance] setBackgroundImage:unselectedBackgroundImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:selectedBackgroundImage
forState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:bothUnselectedImage
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:leftSelectedImage
forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:rightSelectedImage
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
これをコメントアウトすると、ラベルは問題なく表示されます...しかし、背景画像が必要です....では、ios7でカスタマイズされたセグメント化されたコントロールを持ちながら、ios6の互換性を維持するにはどうすればよいですか