ios总结
延迟执行:
########################################################################################
// 创建延期的时间 2S,因为dispatch_time使用的时间是纳秒,尼玛,比毫秒还小,太夸张了!!!
double delayInSeconds = 0;
dispatch_time_t delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, (int64_t) (delayInSeconds * NSEC_PER_SEC));
// 延期执行 dispatch_after(delayInNanoSeconds, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
。。。。
});
#####################################################################################
退出键盘(取消view上的所有响应者):
#####################################################################################
[self.view endEditing:YES];
本地存储:
#####################################################################################
- (void)updateUserInUserDefaults{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:passWord forKey:@"password"]; [userDefaults synchronize];
}
账号和密码框:
// 生成账号输入框 _loginNameField = [[UITextField alloc] init]; [_loginNameField setX:loginInputView.frame.origin.x + 50]; [_loginNameField setY:loginInputView.frame.origin.y]; [_loginNameField setWidth:loginInputView.frame.size.width - 50]; [_loginNameField setHeight:loginInputView.frame.size.height / 2]; _loginNameField.backgroundColor = [UIColor clearColor]; _loginNameField.placeholder = @"请输入账号名"; _loginNameField.borderStyle = UITextBorderStyleNone; _loginNameField.font = [UIFont systemFontOfSize:15]; _loginNameField.textColor = HexGRAY(0x11, 255); _loginNameField.keyboardType = UIKeyboardTypeDefault; _loginNameField.returnKeyType = UIReturnKeyDefault; _loginNameField.clearButtonMode = UITextFieldViewModeWhileEditing; [self.view addSubview:_loginNameField]; // 生成密码输入框 _passwordField = [[UITextField alloc] init]; [_passwordField setX:loginInputView.frame.origin.x + 50]; [_passwordField setY:loginInputView.frame.origin.y + loginInputView.frame.size.height / 2]; [_passwordField setWidth:loginInputView.frame.size.width - 50]; [_passwordField setHeight:loginInputView.frame.size.height / 2]; _passwordField.backgroundColor = [UIColor clearColor]; _passwordField.placeholder = @"请输入密码"; _passwordField.borderStyle = UITextBorderStyleNone; _passwordField.font = [UIFont systemFontOfSize:15]; _passwordField.textColor = HexGRAY(0x11, 255); _passwordField.keyboardType = UIKeyboardTypeDefault; _passwordField.returnKeyType = UIReturnKeyDefault; _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing; _passwordField.secureTextEntry = YES; [self.view addSubview:_passwordField];
图片拉伸:第一个参数表示左边多少不拉伸(针对宽度), 第二个参数表示上面多少不拉伸(针对高度)
UIImage *loginBtnImage = [[UIImage imageNamed:@"btn"] stretchableImageWithLeftCapWidth:10 topCapHeight:4];
格式化字符串:
NSDateFormatter *dateToStringFormatter = [[NSDateFormatter alloc] init];
[dateToStringFormatter setDateFormat:@"yyyy"];
return [dateToStringFormatter stringFromDate:[NSDate date]];

浙公网安备 33010602011771号