#import "mendchildViewController.h"
@interface mendchildViewController ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
@property(nonatomic,strong)UITableView *onetableview;
@end
@implementation mendchildViewController
-(void)viewDidAppear:(BOOL)animated{
self.navigationItem.title = @"修改孩子信息"; self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor colorWithRed:55.0/255 green:55.0/255 blue:55.0/255 alpha:1]};
self.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"sk2"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self setNeedsStatusBarAppearanceUpdate];
self.navigationController.navigationBar.translucent = NO;
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:242.0/255 green:242.0/255 blue:242.0/255 alpha:1];
_onetableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 325) style:UITableViewStylePlain];
_onetableview.delegate = self;
_onetableview.dataSource = self;
_onetableview.backgroundColor = [UIColor orangeColor];
[self.view addSubview:_onetableview];
_onetableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
_redbtn = [[UIButton alloc]init];
[_redbtn setTitle:@"保存" forState:UIControlStateNormal];
_redbtn.layer.cornerRadius = 2.0;
_redbtn.backgroundColor = weizicolor;
[_redbtn addTarget:self action:@selector(clickred) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_redbtn];
[_redbtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view.mas_centerX);
make.top.mas_equalTo(345);
make.left.mas_equalTo(40 *screenRation);
make.right.mas_equalTo(-40 *screenRation);
}];
}
//从相册中读取
-(void)readImageFromAlbum{
//创建对象
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//(选择类型)表示仅仅从相册中选取照片
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//指定代理,因此我们要实现UIImagePickerControllerDelegate,UINavigationControllerDelegate协议
imagePicker.delegate = self;
//设置在相册选完照片后,是否跳到编辑模式进行图片剪裁。(允许用户编辑)
imagePicker.allowsEditing = YES;
//显示相册
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)readImageFromCamera{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES; //允许用户编辑
[self presentViewController:imagePicker animated:YES completion:nil];
} else {
//弹出窗口响应点击事件
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"未检测到摄像头" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
}
}
//图片完成之后处理
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
//image 就是修改后的照片
//将图片添加到对应的视图上
//初始化imageNew为从相机中获得的--
_headview.image = image;
[self dismissViewControllerAnimated:YES completion:nil];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 6;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0) {
return 100;
}
return 45;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0) {
UITableViewCell *viewcell = [UITableViewCell new];
_headview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"baby"]];
_headview.layer.cornerRadius = 30.0;
_headview.layer.masksToBounds = YES;
[_headview addTapGestureRecognizerWith:self action:@selector(clickhead:)];
[viewcell.contentView addSubview:_headview];
[_headview mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(viewcell.contentView.mas_centerX);
// make.centerY.mas_equalTo(viewcell.contentView.mas_centerY);
make.size.mas_equalTo(CGSizeMake(60, 60));
make.top.mas_equalTo(10);
}];
_bottomLabel = [[UILabel alloc]init];
_bottomLabel.text = @"点击修改头像";
_bottomLabel.textColor = ILuColor(51, 51, 51);
_bottomLabel.textAlignment = NSTextAlignmentCenter;
_bottomLabel.font = [UIFont systemFontOfSize:24*screenRation];
[viewcell.contentView addSubview:_bottomLabel];
[_bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(viewcell.mas_centerX);
make.top.mas_equalTo(_headview.mas_bottom).offset(10);
make.size.mas_equalTo(CGSizeMake(80, 12));
}];
return viewcell;
}else if (indexPath.row==1){
UITableViewCell *viewcell = [UITableViewCell new];
UILabel *label = [[UILabel alloc]init];
label.text = @"孩子昵称:";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:32*screenRation];
label.textColor = ILuColor(51, 51, 51);
[viewcell addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 12));
}];
_namefield = [[UITextField alloc]init];
//_namefield.text = @"雨";
_namefield.placeholder = @"昵称";
_namefield.textAlignment= NSTextAlignmentRight;
_namefield.backgroundColor = [UIColor clearColor];
_namefield.textColor = [UIColor blackColor];
_namefield.font = [UIFont systemFontOfSize:18];
_namefield.delegate = self;
[_namefield addTarget:self action:@selector(valuechanged:) forControlEvents:UIControlEventAllEditingEvents];
[viewcell addSubview:_namefield];
[_namefield mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 18));
}];
return viewcell;
}else if (indexPath.row==2){
UITableViewCell *viewcell = [UITableViewCell new];
UILabel *label = [[UILabel alloc]init];
label.text = @"孩子年龄:";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:32*screenRation];
label.textColor = ILuColor(51, 51, 51);
[viewcell addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 12));
}];
_yearfield = [[UITextField alloc]init];
//_yearfield.text = @"2岁";
_yearfield.placeholder =@"2岁";
_yearfield.textAlignment= NSTextAlignmentRight;
_yearfield.backgroundColor = [UIColor clearColor];
//_namefield.backgroundColor = [UIColor redColor];
_yearfield.textColor = [UIColor blackColor];
_yearfield.font = [UIFont systemFontOfSize:18];
_yearfield.delegate = self;
[viewcell addSubview:_yearfield];
[_yearfield mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.right.mas_equalTo(-40 *screenRation);
make.size.mas_equalTo(CGSizeMake(120, 18));
}];
return viewcell;
}else if (indexPath.row==3){
UITableViewCell *viewcell = [UITableViewCell new];
UILabel *label = [[UILabel alloc]init];
label.text = @"孩子性别:";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:32*screenRation];
label.textColor = ILuColor(51, 51, 51);
[viewcell addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 12));
}];
_sexfield = [[UITextField alloc]init];
//_sexfield.text = @"性别";
_sexfield.placeholder = @"性别";
_sexfield.textAlignment= NSTextAlignmentRight;
_sexfield.textColor = ILuColor(51, 51, 51);
_sexfield.font = [UIFont systemFontOfSize:18];
_sexfield.delegate = self;
// [_sexfield addTarget:self action:@selector(clickfield:) forControlEvents:UIControlEventValueChanged];
[viewcell addSubview:_sexfield];
[_sexfield mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 18));
}];
return viewcell;
}else if (indexPath.row==4){
UITableViewCell *viewcell = [UITableViewCell new];
UILabel *label = [[UILabel alloc]init];
label.text = @"孩子体重(kg):";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:32*screenRation];
label.textColor = ILuColor(51, 51, 51);
[viewcell addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 12));
}];
_weightfield = [[UITextField alloc]init];
//_weightfield.text = @"25.0";
_weightfield.placeholder =@"体重";
_weightfield.textAlignment= NSTextAlignmentRight;
_weightfield.textColor = ILuColor(51, 51, 51);
_weightfield.font = [UIFont systemFontOfSize:18];
_weightfield.delegate = self;
[viewcell addSubview:_weightfield];
[_weightfield mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 18));
}];
return viewcell;
}
UITableViewCell *viewcell = [UITableViewCell new];
UILabel *label = [[UILabel alloc]init];
label.text = @"孩子身高(cm):";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:32*screenRation];
label.textColor = ILuColor(51, 51, 51);
[viewcell addSubview:label];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 12));
}];
_heightfield = [[UITextField alloc]init];
//_heightfield.text = @"36.0";
_heightfield.placeholder = @"身高";
_heightfield.textAlignment= NSTextAlignmentRight;
_heightfield.textColor = ILuColor(51, 51, 51);
_heightfield.font = [UIFont systemFontOfSize:18];
_heightfield.delegate = self;
[viewcell addSubview:_heightfield];
[_heightfield mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-40 *screenRation);
make.centerY.mas_equalTo(viewcell.mas_centerY);
make.size.mas_equalTo(CGSizeMake(120, 18));
}];
return viewcell;
}
-(void)valuechanged:(UITextField *)textfield{
NSLog(@"输出textfield的值:%@",textfield.text);
}
//-(void)textFieldDidEndEditing:(UITextField *)textField{
// UITableViewCell *cell = (UITableViewCell*)[textField superview];
// NSIndexPath *indexPath = [_onetableview indexPathForCell:cell];
// if (indexPath.row==1) {
// NSLog(@"输出textfield.text的值:%@",textField.text);
// }else if (indexPath.row==2){
// NSLog(@"输出textfield.text的值:%@",textField.text);
// }else if (indexPath.row==3){
// NSLog(@"输出textfield.text的值:%@",textField.text);
// }else if (indexPath.row==4){
// NSLog(@"输出textfield.text的值:%@",textField.text);
// }else if (indexPath.row==5){
// NSLog(@"输出textfield.text的值:%@",textField.text);
// }
//}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
UITableViewCell *cell = (UITableViewCell *)[textField superview];
NSIndexPath *indexPath = [_onetableview indexPathForCell:cell];
if (indexPath.row==1) {
NSLog(@"输出textfield.text的值:%@",textField.text);
}else if (indexPath.row==2){
NSLog(@"输出textfield.text的值:%@",textField.text);
}else if (indexPath.row==3){
NSLog(@"输出textfield.text的值:%@",textField.text);
}else if (indexPath.row==4){
NSLog(@"输出textfield.text的值:%@",textField.text);
}else if (indexPath.row==5){
NSLog(@"输出textfield.text的值:%@",textField.text);
}
}
-(void)clickhead:(UITapGestureRecognizer *)sender{
//NSLog(@"点击的是head");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *imageAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self readImageFromAlbum];
}];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self readImageFromCamera];
}];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:imageAction];
[alertController addAction:cameraAction];
[alertController addAction:cancleAction];
[self presentViewController:alertController animated:YES completion:^{
}];
}
-(void)clickred{
NSLog(@"保存");
}
-(void)clickbtn2{
NSLog(@"点击的是头像2");
}