我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加了padding。
;
但是,该问题在模拟器或 iOS7 iphone 4s 设备上均未出现。
我的配置如下
任何人都可以指出什么可能是错的?提前致谢
我遇到了一个问题。工具栏在iOS7 iphone 5s真机前添加了padding。
;
但是,该问题在模拟器或 iOS7 iphone 4s 设备上均未出现。
我的配置如下
任何人都可以指出什么可能是错的?提前致谢
即使我遇到了同样的问题(但是,在模拟器和设备中都看到了它)。我使用setWidth
消息来限制每个段的宽度。所以,像: -
[segmentedControl setWidth:75.0f forSegmentAtIndex:0];
应该解决这个问题。虽然我没有使用故事板
我对这个修复并不感到自豪,但它确实为我修复了它:
// in the app delegate class
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
// in the view
- (void)fixToolbarWidth
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
float adjust = -10.5f;
// self.toolbar is linked to the UIToolbar
self.toolbar.frame = CGRectMake(adjust, 0, [SizeHelper getSizeInOrientation].width-adjust, self.toolbar.frame.size.height);
// self.segmentedControl is linked to the UISegmentedControl
self.segmentedControl.frame = CGRectMake(0, 0, self.toolbar.frame.size.width+(adjust*2), self.segmentedControl.frame.size.height);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// fix on first load
[self fixToolbarWidth];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
// resize if they rotate the device
[self fixToolbarWidth];
}
更新/更简单的版本
只要您的工具栏和分段控制器正确设置为缩放 .xib 文件中的全宽,您就可以在viewDidLoad
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
// use a different adjustment for iPad vs iPhone/touch
float adjust = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? -14.0f : -9.0f;
self.toolbar.frame = CGRectMake(adjust, 0, self.toolbar.frame.size.width-adjust, self.toolbar.frame.size.height);
self.segmentedControl.frame = CGRectMake(0, 0, self.segmentedControl.frame.size.width+adjust, self.segmentedControl.frame.size.height);
}
我也遇到同样的问题。我所做的是将段控件从工具栏上移出。这对我有用。