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];
}
相关推荐
鹤卿1237 小时前
(OC)UI学习——网易云仿写
ui·ios·objective-c
不自律的笨鸟7 小时前
最新屏蔽 iOS 系统更新描述文件保姆级教程
ios
开心猴爷8 小时前
Flutter 如何自动上传 可以 IPA 把构建和上传分开处理
后端·ios
秋雨梧桐叶落莳12 小时前
iOS——QQ音乐仿写项目总结
学习·macos·ui·ios·mvc·objective-c·xcode
iUNPo14 小时前
WWDC26 技术解读:Apple Intelligence、Siri AI 与苹果生态的下一步
macos·ios·wwdc
代码的小搬运工14 小时前
【iOS】谓词与正则表达式
ios
恋猫de小郭15 小时前
解析华为 DevEco Code 和小米 MiMo Code,都基于 OpenCode ,有什么区别?
android·前端·ios
wjm0410061 天前
ios内存管理
ios·objective-c·swift·客户端开发
黑科技iOS上架1 天前
ios应用被封号后再次上架很难么?
经验分享·ios
柚鸥ASO优化1 天前
一篇讲透安卓ASO!开发者千万别只盯着iOS了
android·ios·aso优化