如何为所有版本的ios编写UIButton的代码,如ios6& ios7 3.5英寸和4英寸屏幕

时间:2014-04-17 07:13:07

标签: ios iphone objective-c

我想创建一个同时在iPhone 4和5以及3G上运行的应用程序。我写的是这样的。但它在ios 6& ios7 4英寸屏幕。这是我的代码。帮助我任何身体。

#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

- (void)viewDidLoad
{
    if(IS_WIDESCREEN) {
        weeklyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
        [weeklyAudio addTarget:self action:@selector(weeklyPredictions)    forControlEvents:UIControlEventTouchUpInside];
        [weeklyAudio setTitle:@"WEEKLY PREDICTIONS" 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, 70, 140, 100);
        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];
    } else {
        weeklyAudio=[UIButton buttonWithType:UIButtonTypeCustom];
        [weeklyAudio addTarget:self action:@selector(weeklyPredictions) forControlEvents:UIControlEventTouchUpInside];
        [weeklyAudio setTitle:@"WEEKLY PREDICTIONS" 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, 70, 140, 100);
        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];
    }
}

0 个答案:

没有答案