我正在开发iOS7& iOS6(3.5英寸和4英寸屏幕)。
我的问题是在iOS7 4-inches
屏幕显示正确的方式。在具有4英寸屏幕的iOS 6中,它无法正常显示。我有对齐问题。带有3.5英寸的iOS7也出现了一些对齐问题。但是3.5英寸的iOS6显示效果很好。
我不知道如何修复对齐问题。这是我的示例代码:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
- (void)viewDidLoad
{
[super viewDidLoad];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
naviBarObj=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 20, 320, 64)];
[self.view addSubview:naviBarObj];
[naviBarObj setBarTintColor:[UIColor colorWithRed:38.0f/255.0f green:45.0f/255.0f blue:51/255.0f alpha:1.0]];
// Weekly Audio Button Creation..
weeklyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
[weeklyAudio addTarget:self action:@selector(weeklyPredictions) forControlEvents:UIControlEventTouchUpInside];
[weeklyAudio setTitle:@"WEEKLY" forState:UIControlStateNormal];
weeklyAudio.titleLabel.textAlignment = NSLineBreakByWordWrapping;
weeklyAudio.titleLabel.numberOfLines = 2;
[weeklyAudio.titleLabel setTextAlignment: NSTextAlignmentCenter];
[weeklyAudio setTitleEdgeInsets:UIEdgeInsetsMake(60, 10, 10, 10)];
[weeklyAudio.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
weeklyAudio.frame=CGRectMake(10, 100, 140, 120);
weeklyAudio.layer.cornerRadius=5;
weeklyAudio.backgroundColor=[UIColor colorWithRed:232.0f/255.0f green:52.0f/255.0f blue:27.0f/255.0f alpha:1.0];
[self.view addSubview:weeklyAudio];
weeklyAudioImage=[[UIImageView alloc]initWithFrame:CGRectMake(45, 10, 48, 48)];
weeklyAudioImage.image=[UIImage imageNamed:@"48*48.png"];
[weeklyAudio addSubview:weeklyAudioImage];
weeklyAudio.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
// Create Yearly Audio Button.
yearlyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
[yearlyAudio addTarget:self action:@selector(yearlyPredictions) forControlEvents:UIControlEventTouchUpInside];
[yearlyAudio setTitle:@"YEARLY" forState:UIControlStateNormal];
yearlyAudio.titleLabel.textAlignment=NSLineBreakByWordWrapping;
yearlyAudio.titleLabel.numberOfLines=2;
[yearlyAudio.titleLabel setTextAlignment:NSTextAlignmentCenter];
[yearlyAudio setTitleEdgeInsets:UIEdgeInsetsMake(60, 10, 10, 10)];
[yearlyAudio.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
yearlyAudio.frame=CGRectMake(160, 100, 140, 120);
yearlyAudio.layer.cornerRadius=5;
yearlyAudio.backgroundColor=[UIColor colorWithRed:16.0f/255.0f green:144.0f/255.0f blue:209.0f/255.0f alpha:1.0];
[self.view addSubview:yearlyAudio];
yearlyAudioImage=[[UIImageView alloc]initWithFrame:CGRectMake(45, 10, 48, 48)];
yearlyAudioImage.image=[UIImage imageNamed:@"48*48.png"];
[yearlyAudio addSubview:yearlyAudioImage];
yearlyAudio.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
// iAD integration.
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame=CGRectMake(0, 580, 320, 40);
adView.delegate=self;
adView.autoresizingMask =UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
}
else
{
weeklyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
[weeklyAudio addTarget:self action:@selector(weeklyPredictions) forControlEvents:UIControlEventTouchUpInside];
[weeklyAudio setTitle:@"WEEKLY" forState:UIControlStateNormal];
weeklyAudio.titleLabel.textAlignment = NSLineBreakByWordWrapping;
weeklyAudio.titleLabel.numberOfLines = 2;
[weeklyAudio.titleLabel setTextAlignment: NSTextAlignmentCenter];
[weeklyAudio setTitleEdgeInsets:UIEdgeInsetsMake(60, 10, 10, 10)];
[weeklyAudio.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
weeklyAudio.frame=CGRectMake(10, 50, 140, 110);
weeklyAudio.layer.cornerRadius=5;
weeklyAudio.backgroundColor=[UIColor colorWithRed:232.0f/255.0f green:52.0f/255.0f blue:27.0f/255.0f alpha:1.0];
[self.view addSubview:weeklyAudio];
weeklyAudioImage=[[UIImageView alloc]initWithFrame:CGRectMake(45, 10, 48, 48)];
weeklyAudioImage.image=[UIImage imageNamed:@"48*48.png"];
[weeklyAudio addSubview:weeklyAudioImage];
weeklyAudio.autoresizingMask =UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
// Create Yearly Button Audio
yearlyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
[yearlyAudio addTarget:self action:@selector(yearlyPredictions) forControlEvents:UIControlEventTouchUpInside];
[yearlyAudio setTitle:@"YEARLY" forState:UIControlStateNormal];
yearlyAudio.titleLabel.textAlignment = NSLineBreakByWordWrapping;
yearlyAudio.titleLabel.numberOfLines = 2;
[yearlyAudio.titleLabel setTextAlignment: NSTextAlignmentCenter];
[yearlyAudio setTitleEdgeInsets:UIEdgeInsetsMake(60, 10, 10, 10)];
[yearlyAudio.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
yearlyAudio.frame=CGRectMake(160, 50, 140, 110);
yearlyAudio.layer.cornerRadius=5;
yearlyAudio.backgroundColor=[UIColor colorWithRed:16.0f/255.0f green:144.0f/255.0f blue:209.0f/255.0f alpha:1.0];
[self.view addSubview:yearlyAudio];
yearlyAudioImage=[[UIImageView alloc]initWithFrame:CGRectMake(45, 10, 48, 48)];
yearlyAudioImage.image=[UIImage imageNamed:@"48*48.png"];
[yearlyAudio addSubview:yearlyAudioImage];
yearlyAudio.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame=CGRectMake(0, 410, 320, 40);
adView.delegate=self;
[self.view addSubview:adView];
}
}