当前位置: 首页 > article >正文

UIkit-UIAlertContent

简单Demo

//注意!!!必须放在viewController的viewDidAppear里面,viewDidLoad里面不行
- (void)viewDidAppear:(BOOL)animated
{
    // 创建 UIAlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是消息" preferredStyle:UIAlertControllerStyleAlert];
    
    //添加自定义文本框
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
         //自定义文本框
        textField.placeholder = @"这是第一个文本框";
        textField.keyboardType = UIKeyboardTypeDefault;
    }];
    
    //添加第二个自定义文本框
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
         //自定义文本框
        textField.placeholder = @"这是第二个文本框";
        textField.keyboardType = UIKeyboardTypeDefault;
    }];
    
    UIAlertAction *okAction = [UIAlertAction
        actionWithTitle:@"确定"
                  style:UIAlertActionStyleDefault
                handler:^(UIAlertAction *action) {
                    // 处理确定按钮点击
                    UITextField *textField = alertController.textFields.firstObject;
                    NSString *enteredText = textField.text;
        
                    UITextField *secTextField = alertController.textFields[1];
                    NSString *secText = secTextField.text;
                    // 根据需要处理输入的文本
                }];

    [alertController addAction:okAction];
    
    
    alertController.popoverPresentationController.sourceView = self.view;
    alertController.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds), 1.0, 1.0);


    // 在视图控制器中显示 UIAlertController
    [self presentViewController:alertController animated:YES completion:nil];
    
}
    
}

在这里插入图片描述
后面的界面会置灰

position

[UIAlertController alertControllerWithTitle:@“标题” message:@“这是消息” preferredStyle:UIAlertControllerStyleAlert];

UIAlertControllerStyleAlert
alert样式在屏幕中间

actionsheet的样式
在这里插入图片描述
actionsheet不能添加文本框

添加文本框

addTextFieldWithConfigurationHandler
在这里插入图片描述
上面代码有事例

其他控件

UIStepper

在这里插入图片描述

- (void)showStepView
{
    // 创建一个标签用于显示数值
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 300, 200, 30)];
    self.label.textColor = [UIColor blackColor];
    self.label.text = @"0.0";
    [self.view addSubview:self.label];

    // 创建一个 UIStepper
    self.stepper = [[UIStepper alloc] initWithFrame:CGRectMake(50, 350, 0, 0)];
    [self.stepper addTarget:self action:@selector(stepperValueChanged) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.stepper];
}

- (void)stepperValueChanged
{
    self.label.text = [NSString stringWithFormat:@"stepValue:%f",self.stepper.value];
}

http://www.kler.cn/news/155555.html

相关文章:

  • Django之ORM
  • 1、输入一行字符,分别统计出其中的英文字母、空格、数字和其他字符的个数。
  • Google Guava 区间工具使用详解
  • Spring的创建
  • 【滑动窗口】水果成篮
  • Python如何优雅地使用重试:tenacity
  • C++11——initializer_list
  • 初识主力投资者
  • Linux MeterSphere一站式开源持续测试平台远程访问
  • JavaSE学习路线及经验所谈
  • selenium使用记录
  • 1949-2021年全国31省公路里程数据
  • Docker容器(一)概述
  • Python安装步骤介绍
  • LeetCode 每日一题 Day1
  • 软件工程导论学习资料
  • 7.24 SpringBoot项目实战【审核评论】
  • 音乐播放器Swinsian mac功能介绍
  • 提权(2), Netcat反弹shell
  • html页面多个视频标签时设定只能播放一个视频
  • 视频智能分析国标GB28181云平台EasyCVR加密机授权异常是什么原因?
  • Java数据结构 之 包装类简单认识泛类
  • 操作系统进程与线程篇
  • 【Unity动画】什么是动画蒙版(Avatar Mask)
  • 【面试经典 150 | 二分查找】搜索插入位置
  • 【STL】手撕 string类
  • Python练习题(二)
  • re:Invent 构建未来:云计算生成式 AI 诞生科技新局面
  • IO_D3(231205)
  • Python datetime 字符串 相互转 datetime