1:UITextField设置出现清除按键
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
说明:
UITextField.clearButtonMode:清空输入的字符,有以下几种模式
UITextFieldViewModeAlways,不为空,获得焦点与没有获得焦点都显示清空按钮
UITextFieldViewModeNever,不显示清空按钮
UITextFieldViewModeWhileEditing,不为空,且在编辑状态时(及获得焦点)显示清空按钮
UITextFieldViewModeUnlessEditing, 不为空,且不在编译状态时(焦点不在输入框上)显示清空按钮
扩展:关于键盘类型(UITextField.keyboardType),UITextField.enablesReturnKeyAutomatically = YES当UITextField不为空时高亮,[UITextField ResignFirstResponder]关闭键盘
2:绘画一条下划线
通过一个视图,定义其位置跟背景就可以,下面代码仅供参考 self.backgroundView = nil; self.backgroundColor = [UIColor clearColor]; UIView* _lineView = [[UIView alloc] initWithFrame:CGRectMake(kInput_OnlyText_Cell_LeftPading, 43.5, kScreen_Width-2*kInput_OnlyText_Cell_LeftPading, 0.5)]; _lineView.backgroundColor = [UIColor colorWithHexString:@"0xaebdc9"]; [self.contentView addSubview:_lineView];
3:表格一些设置
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;//不加换行线 self.myTableView.backgroundColor = [UIColor colorWithHexString:@"0xfafafa"]; UIView *upBgView = [[UIView alloc] initWithFrame:self.view.bounds]; upBgView.backgroundColor =[UIColor colorWithHexString:@"0x29333f"]; [upBgView setY:-CGRectGetHeight(upBgView.bounds)]; [self.myTableView addSubview:upBgView]; self.myTableView.contentInset = UIEdgeInsetsMake(-kHigher_iOS_6_1_DIS(20), 0, 0, 0);//缩进 self.myTableView.tableFooterView=[self customFooterView];//方法 返回view,看第五点 self.myTableView.tableHeaderView = [self customHeaderView]; 扩展: UITableViewCellSelectionStyle选择行的样式UITableViewCellSelectionStyleNone,UITableViewCellSelectionStyleBlue,UITableViewCellSelectionStyleGray 如果要自定义cell的背景色 cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame]]; cell.selectedBackgroundView.backgroundColor = [UIColor redColor]; 改变换行线颜色 tableView.separatorColor = [UIColor blueColor];
4:可以定义表头跟底部视图(代码接上面)
- (UIView *)customHeaderView{ UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 180)]; UIImageView *loginLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_logo"]]; CGFloat loginLogoHeight = CGRectGetHeight(loginLogo.bounds)*kScreen_Width/CGRectGetWidth(loginLogo.bounds); if (loginLogoHeight > 180) { [headerV setHeight:loginLogoHeight]; } loginLogo.frame = CGRectMake(0, 0, kScreen_Width, loginLogoHeight); [headerV addSubview:loginLogo]; return headerV; } - (UIView *)customFooterView{ UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 100)]; _loginBtn = [UIButton buttonWithStyle:StrapSuccessStyle andTitle:@"登录" andFrame:CGRectMake(18, kScreen_Width > 320? 20: 20, kScreen_Width-18*2, 45) target:self action:@selector(sendLogin)]; [footerV addSubview:_loginBtn]; return footerV; }
5:隐藏本页的导航栏
- (void)viewDidLoad { [super viewDidLoad]; [self.navigationController setNavigationBarHidden:YES]; }
6:UIEdgeInsets
typedef struct { CGFloat top, left, bottom, right; } UIEdgeInsets; 主要是理解下UIEdgeInsets在IOS UI里的意义. UIEdgeInsets==>这货其实就是插入间隔区域。正值表示间隔值,负值表示超出参照物的距离。
7:活动指示器UIActivityIndicatorView
可以告知用户有一个操作正在进行中。派生自UIView,所以他是视图,也可以附着在视图上。 UIActivityIndicatorView* activityIndicatorView = [ [ UIActivityIndicatorView alloc ]?initWithFrame:CGRectMake(250.0,20.0,30.0,30.0)]; 设置风格: activityIndicatorView.activityIndicatorViewStyle= UIActivityIndicatorViewStyleGray; UIActivityIndicatorViewStyleWhiteLarge 大型白色指示器 UIActivityIndicatorViewStyleWhite 标准尺寸白色指示器 UIActivityIndicatorViewStyleGray 灰色指示器,用于白色背景 如果希望指示器停止后自动隐藏,那么要设置hidesWhenStoped属性为YES。默认是YES。设置为NO停止后指示器仍会显示。activityIndicatorView.hidesWhenStoped = NO; 显示:可以将它附着在任何视图上,比如表格单元、或者视图,[ self.view addSubview:activityIndicatorView ] 启动和停止 [ activityIndicatorView startAnimating ];//启动 [ activityIndicatorView stopAnimating ];//停止 判断是否处于运动状态isAnimating [activityIndicatorView isAnimating] 下面为一段实例代码 _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray]; CGSize captchaViewSize = _captchaView.bounds.size; _activityIndicator.hidesWhenStopped = YES; [_activityIndicator setCenter:CGPointMake(captchaViewSize.width/2, captchaViewSize.height/2)]; [_captchaView addSubview:_activityIndicator];
8:使用NSUserDefaults保存用户名和密码
创建一个user defaults方法有多个,最简单得快速创建方法: NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults]; 添加数据到 user defaults: [accountDefaults setObject:nameField.text forKey:UserDefaultNameKey]; 也可以添加基本数据类型int, float, bool等,有相应得方法 [accountDefaults setBool:YES forKey:UserDefaultBoolKey]; 从user defaults中获取数据: [accountDefaults objectForKey:NCUserDefaultNameKey] [accountDefaults boolForKey: UserDefaultBoolKey]; 注意:UserDefaults不是立即写入,而是根据时间戳定时的把缓存中的数据写入本地磁盘。所以调用了set方法之后数据有可能还没有写入磁盘应用程序就终止了。可以通过调用synchornize方法强制写入。[[NSUserDefaults standardUserDefaults] synchronize]; 代码片段: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[NSNumber numberWithBool:YES] forKey:kLoginStatus]; [defaults setObject:loginData forKey:kLoginUserDict]; [defaults synchronize];