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];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值