iOS开篇——UI之UIActionSheet

UIActionSheet在iOS8.3之后已不建议使用。 可以使用

UIAlertController+UIAlertControllerStyleActionSheet获得同样的效果

创建UIActionSheet

    UIActionSheet * as = [[UIActionSheet alloc]initWithTitle:@"选择一个英雄" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"德玛" otherButtonTitles:@"琴女", nil];
//设置样式
    as.actionSheetStyle = UIActionSheetStyleBlackOpaque;

实现协议方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"这是第0个");
            break;
        case 1:
            NSLog(@"这是第1个");
            break;
        default:
            break;
    }
}

使用UIAlertController+UIAlertControllerStyleActionSheet实现

    UIAlertController * ac = [UIAlertController alertControllerWithTitle:@"选择一个英雄" message:@"没事" preferredStyle:UIAlertControllerStyleActionSheet];
    [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"取消");
    }]];

    [ac addAction:[UIAlertAction actionWithTitle:@"德玛" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"德玛");
    }]];

    [self presentViewController:ac animated:YES completion:nil];
时间: 2024-12-10 01:39:14

iOS开篇——UI之UIActionSheet的相关文章

iOS开篇——UI之UIGestureRecogzier_手势

一.UITouch 1 //任何视图都可以触发此方法 2 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 3 NSLog(@"视图被触摸了"); 4 } 5 6 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 7 NSLog(@"因意外

iOS开篇——UI之UITableView

1 #import "ViewController.h" 2 3 @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> 4 { 5 //创建数据源 6 NSMutableArray * _dataArray; 7 8 } 9 10 @end 11 12 @implementation ViewController 13 14 - (void)viewDidLoad { 15 [supe

iOS开篇——UI之UITextView

创建UITextView //创建一个单例对象 存储_str字符串 NSUserDefaults * hd = [NSUserDefaults standardUserDefaults]; _str = [hd objectForKey:@"str"]; UITextView * textView = [[UITextView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)]; textView.delegate = self; te

iOS开篇——UI之UAlertView(提示框)

创建提示框 //创建提示框 //标题 提示内容 代理对象 按钮 UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"警告" message:@"萨达姆已经做好战斗准备" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"不确定", nil]; 设置提示框样式

iOS开篇——UI之UITextField

创建文本输入框 UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 250, 40)]; 设置边框样式 textField.borderStyle = UITextBorderStyleRoundedRect; /* typedef NS_ENUM(NSInteger, UITextBorderStyle) { UITextBorderStyleNone, 无效果 UITextBorderS

iOS开篇——UI之UISegmentedControl (分段选择器)

创建分段选择器 UISegmentedControl * sc = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 100, 200, 30)]; [sc insertSegmentWithTitle:@"第一页" atIndex:0 animated:YES]; [sc insertSegmentWithTitle:@"第二页" atIndex:1 animated:YES]; [sc insertS

iOS开篇——UI之UIStepper (计步器)

UIStepper * stepper = [[UIStepper alloc]initWithFrame:CGRectMake(50, 100, 150, 40)]; //********最小值和最大值 stepper.maximumValue = 100; stepper.minimumValue = 0; //设置跃迁值 *** stepper.stepValue = 0.1; //设置镂空颜色 stepper.tintColor = [UIColor redColor]; //添加点击事

iOS开篇——UI之UIView

UIView的几个主要属性 1 /* 2 CGRect frame; 3 4 CGRect bounds; 5 6 CGPoint center; 7 8 CGAffineTransform transform; 9 */ frame 坐标与长宽 center 中心点 bounds 坐标系限制(?) UIView的形变 //view的变形 () //直接形变 view.transform = CGAffineTransformMakeScale(1, 1); //旋转形变 传入一个弧度 view

iOS开篇——UI之UILabel

创建label //创建标签对象 UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 300, 105)]; 添加标示 //添加标示 label.tag = 1; 设置label文字 //设置label文字 // label.text = @"这是一个标签视图,敌军还有三十秒到达战场.碾碎他们"; label.text = @"this is a label!"; 设置label字体位