gpt4 book ai didi

ios - ios6&ios7中4寸屏和3.5寸屏UIButton和UITableview的显示方法

转载 作者:行者123 更新时间:2023-11-29 03:27:03 24 4
gpt4 key购买 nike

我正在开发一个应用程序。在应用程序中,我为 ios7 和 ios6 编写了 3.5 英寸屏幕和 4 英寸屏幕的代码。我拿了一个 View Controller ;在这个 View Controller 中,我想显示两个图像,一个用于顶部,另一个用于底部。还显示登录和注销按钮以及登录 Tableview。在ios7&ios6 3.5寸屏幕和4寸屏幕上显示Top image和Bottom image两张图没有问题。这两个图像显示正确。但是没有显示按钮和 UITableview。我不明白显示 UIButton 和 UITableview 的问题在哪里。请给我想法,任何人。我是编程新手。提前致谢。

下面是我的代码。

Viewcontroller.m(适用于 ios7 和 ios6 的 3.5 英寸和 4 英寸屏幕)。

 if ([[UIScreen mainScreen] bounds].size.height == 568)  
{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];

imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];

// Button Login for ios7 4-inches screen.

btnLogin.frame = CGRectMake(20, 230, 127, 32);

// Create Login for UITableview

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 80, 320, 123) style:UITableViewStyleGrouped];

}

else
{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];

imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];

// Button Login for ios6 4-inches screen.

btnLogin.frame = CGRectMake(20, 230, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 80, 320, 123) style:UITableViewStyleGrouped];

}

imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];

[self.view addSubview:imgLogo];

imgBuilding.image=[UIImage imageNamed:@"image-02.png"];

imgBuilding.alpha=0.4;

[self.view addSubview:imgBuilding];

btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];

[btnLogin setBackgroundImage:[UIImage imageNamed:@"Sign-in-button.png"] forState:UIControlStateNormal];

[self.view addSubview:btnLogin];

// create Login tableview properties

tableVw.dataSource = self;
tableVw.delegate = self;

tableVw.backgroundColor=[UIColor clearColor];

tableVw.scrollEnabled=NO;

tableVw.scrollsToTop=NO;

[self.view addSubview:tableVw];

}

/************ *************** *************** *************** ***/ /*3.5 英寸屏幕适用于 ios6 和 ios7*******************************/

/************ *************** *************** *************** ***/

 else
{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];

imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];

btnLogin.frame = CGRectMake(20, 200, 127, 32);

// create Login Tableview

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

}

else
{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];

imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];

btnLogin.frame = CGRectMake(20, 200, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];

}

imgLogo.image=[UIImage imageNamed:@"Logo-01.png"];

[self.view addSubview:imgLogo];

imgBuilding.image=[UIImage imageNamed:@"image-02.png"];

imgBuilding.alpha=0.4;

[self.view addSubview:imgBuilding];

// Create Button Properties

btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];

[btnLogin setBackgroundImage:[UIImage imageNamed:@"Sign-in-button.png"] forState:UIControlStateNormal];

[self.view addSubview:btnLogin];

// Create Login Tableview properties

tableVw.dataSource = self;
tableVw.delegate = self;

tableVw.backgroundColor=[UIColor clearColor];

tableVw.scrollEnabled=NO;

tableVw.scrollsToTop=NO;

[self.view addSubview:tableVw];


}

}

最佳答案

试试这个代码。我对您的代码进行了更改。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;

UIImageView *imgLogo;
UIImageView *imgBuilding;
UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeCustom];
UITableView *tableVw;
if ([[UIScreen mainScreen] bounds].size.height == 568){

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];

btnLogin.frame = CGRectMake(20, 230, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 123, 320, 100) style:UITableViewStylePlain];
}else{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];

imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];



btnLogin.frame = CGRectMake(20, 210, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 103, 320, 100) style:UITableViewStylePlain];
}

imgLogo.image=[UIImage imageNamed:@"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:@"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];

[btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];
[btnLogin setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:btnLogin];

tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
tableVw.dataSource=self;
tableVw.delegate=self;
[self.view addSubview:tableVw];

}else{

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];

btnLogin.frame = CGRectMake(20, 230, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 127, 300, 100) style:UITableViewStylePlain];
}else{

imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];
btnLogin.frame = CGRectMake(20, 200, 127, 32);

tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStylePlain];
}

imgLogo.image=[UIImage imageNamed:@"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:@"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];

[btnLogin addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchDown];
btnLogin.backgroundColor=[UIColor blackColor];
[self.view addSubview:btnLogin];

tableVw.dataSource = self;
tableVw.delegate = self;
tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
[self.view addSubview:tableVw];
}

}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSString *CellIdentifier =[NSString stringWithFormat:@"%D",indexPath.row];

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

cell.textLabel.text=@"1";


return cell;

}

关于ios - ios6&ios7中4寸屏和3.5寸屏UIButton和UITableview的显示方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20324592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com