![](/img/trans.png)
[英]How to set the Background image for UITableview for ios7 3.5 inches and 4-inches screen
[英]how to display the UIButton and UITableview in ios6&ios7 for 4-inches screen and 3.5 inches screen
我正在開發一個應用程序。 在應用程序中,我為ios7&ios6的3.5英寸屏幕和4英寸屏幕編寫了代碼。 我帶了一個視圖控制器; 在這個視圖控制器中,我想顯示兩個圖像,一個顯示在頂部,另一個顯示在底部,還顯示登錄和注銷按鈕以及登錄Tableview。 在ios7&ios6 3.5英寸屏幕和4英寸屏幕上,顯示兩個圖像(如頂部圖像和底部圖像)沒有問題。 這兩個圖像顯示正確,但是按鈕和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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.