UIkit-UIAlertContent

简单Demo

objectivec 复制代码
//注意!!!必须放在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

objectivec 复制代码
- (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];
}
相关推荐
_瑞10 小时前
深入理解灵动岛
前端·ios·app
黑科技iOS上架12 小时前
分享一个开源的iOS应用AppIcon生成器
经验分享·ios
wabil2 天前
【LVGL】滑动切换页面的界面优化实践
开发语言·ios·swift
威武的花瓣2 天前
调用Page.RegisterAsyncTask()的异步页
ios·iphone
Digitally2 天前
5 种简易方法:摩托罗拉手机数据迁移至 iPhone 17
ios·智能手机·iphone
EricStone4 天前
VibeCoding工程流程学习二:iOS项目架构
ios·vibecoding
天桥吴彦祖6 天前
判断iOS如何监听手机屏幕是否锁屏
ios
敲代码的鱼7 天前
PDF 预览与签名批注写回 支持安卓 iOS 鸿蒙 UTS插件
android·前端·ios
时光足迹7 天前
uni-app 视频通话实战:康复师与患者视频问诊的 6 个致命 Bug 与解决方案
android·ios·uni-app
时光足迹7 天前
JPush UniApp UTS 插件完全参考手册:API、事件与厂商通道一网打尽
vue.js·ios·uni-app