提示框 改变字体

2017-12-04  本文已影响50人  goyohol



UIAlertView

一般使用提示框,会使用“UIAlertView”!

首先遵守<UIAlertViewDelegate>协议!

UIAlertView * alertV = [[UIAlertView alloc] initWithTitle:@"标题" message:@"真的要退出此账号么?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertV show]; //展示提示框

效果:



使用“UIAlertViewDelegate”,响应 按钮点击事件!

#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { //按钮点击

  if (buttonIndex == 1) { //确认按钮
      //确认的操作

  }

}



可通过更改UIAlertView的alertViewStyle属性来实现文字输入的效果。

UIAlertView * alertV = [[UIAlertView alloc] initWithTitle:@"发到邮箱" message:@"请输入邮箱地址" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil]; 
//设置 含有文字输入框
[alertV setAlertViewStyle:UIAlertViewStylePlainTextInput];

[alertV show];


//获取文字输入框(UITextField *)
UITextField * textStrTF = [alertV textFieldAtIndex:0];
textStrTF.keyboardType = UIKeyboardTypeEmailAddress; //邮箱键盘
textStrTF.placeholder = @"请输入邮箱地址";
textStrTF.text = [User_Def objectForKey:USER_EMail]?[User_Def objectForKey:USER_EMail]:@"";
textStrTF.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时有删除按钮

效果:







UIAlertController

改变字体(富文本)的颜色大小时,最好使用UIAlertController
KVC方式 [setValue: forKey:]






UIAlertController添加 文字输入框

[alertcontroller addTextFieldWithConfigurationHandler:^(UITextField *textField){
   textField.placeholder = @"输入文字";
   
}];


效果


表格形式

preferredStyle设置为UIAlertControllerStyleActionSheet!(表格形式


效果: 在屏幕的最底部





使用KVC方式 ([setValue: forKey:]),改变字体的大小和颜色!!












goyohol's essay

上一篇 下一篇

猜你喜欢

热点阅读