ServerSettingViewController.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // ServerSettingViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2017/5/5.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "ServerSettingViewController.h"
  9. @interface ServerSettingViewController ()
  10. @end
  11. @implementation ServerSettingViewController
  12. @synthesize keyboardShow;
  13. /**
  14. viewDidLoad
  15. */
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self initUI];
  19. _serverIpTxt.text=kkServerUrl;
  20. _serverPortTxt.text=kkServerPort;
  21. }
  22. /**
  23. viewWillDisappear
  24. @param animated <#animated description#>
  25. */
  26. -(void)viewWillDisappear:(BOOL)animated
  27. {
  28. //[self.navigationController.navigationBar setHidden:NO];
  29. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification
  30. object:nil];
  31. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification
  32. object:nil];
  33. }
  34. /**
  35. viewDidAppear
  36. @param animated <#animated description#>
  37. */
  38. -(void)viewDidAppear:(BOOL)animated
  39. {
  40. [[NSNotificationCenter defaultCenter] addObserver:self
  41. selector:@selector(keyboardWillShow)
  42. name:UIKeyboardWillShowNotification
  43. object:nil];
  44. [[NSNotificationCenter defaultCenter] addObserver:self
  45. selector:@selector(keyboardWillHide)
  46. name:UIKeyboardWillHideNotification
  47. object:nil];
  48. }
  49. /**
  50. 触摸屏幕
  51. @param touches <#touches description#>
  52. @param event <#event description#>
  53. */
  54. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  55. {
  56. [self.view endEditing:YES];
  57. }
  58. /**
  59. 显示键盘
  60. */
  61. -(void)keyboardWillShow {
  62. // Animate the current view out of the way
  63. if(!keyboardShow){
  64. [UIView animateWithDuration:0.3f animations:^ {
  65. self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-160, self.view.frame.size.width, self.view.frame.size.height);
  66. }];}
  67. keyboardShow=YES;
  68. }
  69. /**
  70. 异常键盘
  71. */
  72. -(void)keyboardWillHide {
  73. // Animate the current view back to its original position
  74. if(keyboardShow){
  75. [UIView animateWithDuration:0.3f animations:^ {
  76. self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+160, self.view.frame.size.width, self.view.frame.size.height);
  77. }];}
  78. keyboardShow=NO;
  79. }
  80. /**
  81. 初始化按钮
  82. */
  83. -(void)initUI{
  84. UIView *contentView=[[UIView alloc]init];
  85. [contentView setBackgroundColor:[UIColor whiteColor]];
  86. [self.view addSubview:contentView];
  87. UIImage *pic=[UIImage imageNamed:@"icon_logo"];
  88. UIImageView *bannerView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)];
  89. [bannerView setImage:pic];
  90. [contentView addSubview:bannerView];
  91. contentView.frame=CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
  92. pic=[UIImage imageNamed:@"loginbg"];
  93. float inputHeight = (self.view.frame.size.width-46)*pic.size.height/pic.size.width;
  94. UIImageView *loginBgImg=[[UIImageView alloc] initWithFrame:CGRectMake(23,self.view.frame.size.height/4,self.view.frame.size.width-46,inputHeight)];
  95. [loginBgImg setImage:[UIImage imageNamed:@"loginbg"]];
  96. [contentView addSubview:loginBgImg];
  97. float lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3;
  98. UILabel *titleLbl=[[UILabel alloc]init];
  99. titleLbl.frame=CGRectMake(contentView.frame.size.width/2-100,lbly,200, 20);
  100. titleLbl.text=@"服务器地址和端口设置";
  101. titleLbl.textAlignment = NSTextAlignmentCenter;
  102. [contentView addSubview:titleLbl];
  103. lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight / 3;
  104. UIImageView *ipImg=[[UIImageView alloc] initWithFrame:CGRectMake(65,lbly,20,15)];
  105. [ipImg setImage:[UIImage imageNamed:@"icon_ip"]];
  106. [contentView addSubview:ipImg];
  107. _serverIpTxt=[[UITextField alloc]init];
  108. _serverIpTxt.frame=CGRectMake(CGRectGetMaxX(ipImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(ipImg.frame) + 10), 20);
  109. _serverIpTxt.font = [UIFont systemFontOfSize:TextFontOfSize];
  110. _serverIpTxt.textAlignment = NSTextAlignmentCenter;
  111. [contentView addSubview: _serverIpTxt];
  112. _serverIpTxt.placeholder=@"服务器地址";
  113. UIView *ipSeparatorView=[[UIView alloc]init];
  114. [ipSeparatorView setBackgroundColor:[UIColor colorWithRed:213.0/255.0 green:213.0/255.0 blue:213.0/255.0 alpha:1]];
  115. ipSeparatorView.frame=CGRectMake(50, CGRectGetMinY(loginBgImg.frame) + inputHeight * 2/ 3-1, loginBgImg.frame.size.width-60, 1);
  116. [contentView addSubview:ipSeparatorView];
  117. lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight *2 / 3;
  118. UIImageView *portImg=[[UIImageView alloc] initWithFrame:CGRectMake(67,lbly,14,18)];
  119. [portImg setImage:[UIImage imageNamed:@"icon_port"]];
  120. [contentView addSubview:portImg];
  121. _serverPortTxt=[[UITextField alloc]init];
  122. _serverPortTxt.font = [UIFont systemFontOfSize:TextFontOfSize];
  123. _serverPortTxt.textAlignment = NSTextAlignmentCenter;
  124. _serverPortTxt.placeholder=@"服务器端口";
  125. _serverPortTxt.frame=CGRectMake(CGRectGetMaxX(portImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(portImg.frame) + 10), 20);
  126. [contentView addSubview: _serverPortTxt];
  127. pic=[UIImage imageNamed:@"bt_save"];
  128. _btnSave=[UIButton buttonWithType:UIButtonTypeCustom];
  129. [_btnSave setBackgroundImage:pic forState:UIControlStateNormal];
  130. _btnSave.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(loginBgImg.frame)+18,200,200*pic.size.height/pic.size.width);
  131. [_btnSave addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
  132. [contentView addSubview:_btnSave];
  133. pic=[UIImage imageNamed:@"bt_back"];
  134. _btnCancel=[UIButton buttonWithType:UIButtonTypeCustom];
  135. [_btnCancel setBackgroundImage:pic forState:UIControlStateNormal];
  136. _btnCancel.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(_btnSave.frame)+18,200,200*pic.size.height/pic.size.width);
  137. [_btnCancel addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  138. [contentView addSubview: _btnCancel];
  139. }
  140. /**
  141. 设定ip和端口
  142. */
  143. -(void)saveData{
  144. kkServerUrl=[_serverIpTxt.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  145. kkServerPort=[_serverPortTxt.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  146. [self dismissViewControllerAnimated:YES completion:nil];
  147. }
  148. /**
  149. 返回按钮
  150. */
  151. -(void)goBack{
  152. [self dismissViewControllerAnimated:YES completion:nil];
  153. }
  154. @end