//
// ViewController.m
// JapaneseDictionary
//
// Created by apple on 14-8-7.
// Copyright (c) 2014年 苹果IOS软件开发者. All rights reserved.
//
#import "ViewController.h"
#import "secondViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
{
UITableView *tableview;
UITextField *textfiled;
}
@end
@implementation ViewController
- (void)createbuttons
{ //1.设置搜索按钮
UIButton *searchbtn = [[UIButton alloc]initWithFrame:CGRectMake(270, 25, 40, 25)];
[searchbtn setTitle:@"翻译"forState:UIControlStateNormal];
[searchbtn addTarget:self action:@selector(didsearch:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:searchbtn];
//2.设置清除按钮
UIButton *clearbtn = [UIButton buttonWithType:UIButtonTypeCustom];
[clearbtn setImage:[UIImage imageNamed:@"clearBtn"] forState:UIControlStateNormal];
clearbtn.frame = CGRectMake(130, 440, 60, 30);
[clearbtn addTarget:self action:@selector(didclear) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:clearbtn];
}
- (void)createTextfiled{
textfiled = [[UITextField alloc] initWithFrame:CGRectMake(80, 25, 180, 25)];
[textfiled setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:textfiled];
}
- (void)createLabel{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 28, 80, 20)];
label.text = [NSString stringWithFormat:@"日语词典"];
label.textColor =[UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
}
- (void)createBackgroundimage
{
UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 17, 320, 49)];
titleImageView.image = [UIImage imageNamed:@"titleView"];
[self.view addSubview:titleImageView];
UIImageView *footerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 49, 320, 49)];
footerImageView.image = [UIImage imageNamed:@"bottomBg"];
[self.view addSubview:footerImageView];
}
- (void)didsearch:(UIButton *)sender
{
tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, 300, self.view.frame.size.height-118) style:UITableViewStylePlain];
tableview.dataSource = self;
tableview.delegate = self;
tableview.rowHeight = 40;
[self.view addSubview:tableview];
}
- (void)didclear
{
//移除当前桌面
[tableview removeFromSuperview];
textfiled.text [email protected]"";
}
- (void)viewDidLoad {
[super viewDidLoad];
[self createBackgroundimage];
[self createTextfiled];
[self createLabel];
[self createbuttons];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//返回表格的行数
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//获取已有的Cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
//创建一个Cell
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
//在Cell上显示文字
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
secondViewController *secondCtrl = [[secondViewController alloc] init];
//弹出查询结果界面
[self presentViewController:secondCtrl animated:YES completion:nil];
}
@end
//
// secondViewController.m
// JapaneseDictionary
//
// Created by apple on 14-8-7.
// Copyright (c) 2014年 苹果IOS软件开发者. All rights reserved.
//
#import "secondViewController.h"
@interface secondViewController ()
@end
@implementation secondViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)AddButtons
{
//1.设置返回按钮
UIButton * backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backbtn setImage:[UIImage imageNamed:@"backBtn"] forState:UIControlStateNormal];
backbtn.frame = CGRectMake(20, 30, 50, 30);
[backbtn addTarget:self action:@selector(didback) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backbtn];
//2.设置发音按钮
UIButton * pronouncebtn = [UIButton buttonWithType:UIButtonTypeCustom];
[pronouncebtn setImage:[UIImage imageNamed:@"pronounceBtn_01"] forState:UIControlStateNormal];
//按下去是高亮状态
[pronouncebtn setImage:[UIImage imageNamed:@"pronounceBtn_02"] forState:UIControlStateHighlighted];
pronouncebtn.frame = CGRectMake(255, 30, 50, 30);
[pronouncebtn addTarget:self action:@selector(didpronounce) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:pronouncebtn];
}
- (void)AddLabel{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 35, 280, 460)];
label.text = [NSString stringWithFormat:@"信息"];
label.textColor =[UIColor blackColor];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIImageView *resultview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 14, 320,self.view.frame.size.height - 14)];
resultview.image = [UIImage imageNamed:@"tips_line"];
[self.view addSubview:resultview];
[self AddButtons];
[self AddLabel];
}
- (void)didback
{
//使模态视图消失
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didpronounce
{
}