ios ~ UIAlertcontroller 设置字体颜色

2022-01-15  本文已影响0人  阳光下的叶子呵

ios 系统提示框 改变字体

UIAlertView

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

首先遵守<UIAlertViewDelegate>协议!

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

效果:

[图片上传失败...(image-b5adbf-1642215038552)]

使用“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; //编辑时有删除按钮
复制代码

效果:

[图片上传失败...(image-74266c-1642214646018)]



UIAlertController

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

UIAlertController添加 文字输入框

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

效果

[图片上传失败...(image-a2d866-1642214646018)]

表格形式

preferredStyle设置为UIAlertControllerStyleActionSheet! (表格形式

效果: 在屏幕的最底部




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

上一篇 下一篇

猜你喜欢

热点阅读