美文网首页
提示框 改变字体

提示框 改变字体

作者: goyohol | 来源:发表于2017-12-04 16:36 被阅读50次



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:]

  • 改变 按钮字体颜色
    NSString * titleStr = NSLocalizedString(@"标题", nil); //标题
    
    UIAlertController * alertcontroller = [UIAlertController alertControllerWithTitle: titleStr message:@"真的要退出此账号么?" preferredStyle:UIAlertControllerStyleAlert];
    
    //确认按钮
    UIAlertAction *sureAction=[UIAlertAction actionWithTitle:NSLocalizedString(@"确定", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //确认的操作
    
    }];
    UIColor * changeColor = [UIColor redColor]; //颜色
    [sureAction setValue: changeColor forKey:@"titleTextColor"]; //KVC:改变字体颜色
    
    //取消按钮
    UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:NSLocalizedString(@"取消", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //取消的操作
    
    }];
    //[cancelAction setValue:[UIColor greenColor] forKey:@"titleTextColor"]; //KVC:改变字体颜色
    
    //将UIAlertAction项 添加到UIAlertController
    [alertcontroller addAction:cancelAction];
    [alertcontroller addAction: sureAction];
    
    
    //present 显示alertcontroller
    [self presentViewController:alertcontroller animated:YES completion:nil];
    

    效果:




  • 改变标题、及提示信息的字体:(富文本)
    //改变title的大小和颜色
    NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:titleStr];
    [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16.f] range:NSMakeRange(0, titleStr.length)];
    [titleAtt addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, titleStr.length)];
    //KVC:改变字体(富文本)
    [alertcontroller setValue:titleAtt forKey:@"attributedTitle"];
    
    
    NSString * messageStr = @"真的要退出此账号么?";
    //改变message的大小和颜色
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:messageStr];
    [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.f] range:NSMakeRange(0, messageStr.length)];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:[UIColor cyanColor] range:NSMakeRange(0, messageStr.length)];
    //KVC:改变字体(富文本)
    [alertcontroller setValue:messageAtt forKey:@"attributedMessage"];
    

    效果:



UIAlertController添加 文字输入框

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


效果


表格形式

preferredStyle设置为UIAlertControllerStyleActionSheet!(表格形式


效果: 在屏幕的最底部





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












goyohol's essay

相关文章

  • ios ~ UIAlertcontroller 设置字体颜色

    ios 系统提示框 改变字体[https://juejin.cn/post/6972634888344174600...

  • 提示框 改变字体

    UIAlertView 一般使用提示框,会使用“UIAlertView”! 首先遵守 协议! 效果: 使用“UIA...

  • Swift UI 20 自定制UIAlertControlle

    1:系统提供的提示框如下所示: 2: 自定制提示框如下: 3: 所用到的方法 (1)可同时改变字体大小及颜色(第一...

  • css文本

    字体 改变字号 font-size 改变字体 font-family 加粗字体 font-weight 倾斜字体...

  • 「CSS」文本

    字体改变字号改变字体加粗字体倾斜字体更改行距font shorthand改变文字颜色 对齐方式文字居中文本垂直对齐...

  • Vue v-bind:的使用

    点击跳转 字体改变颜色 class改变字体颜色 红色字体