如何更改UIAlertController cornerRadius

时间:2017-04-11 03:56:01

标签: ios objective-c uialertcontroller

我创建了一个像这样的UIAlertController:

    UIAlertController deleteView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    deleteView.view.layer.cornerRadius = 100;
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"delete" style:UIAlertActionStyleDefault handler:nil];
    [cancelAction setValue:[NSNumber numberWithInteger:NSTextAlignmentLeft] forKey:@"titleTextAlignment"];
    [cancelAction setValue:[UIColor blackColor] forKey:@"titleTextColor"];

我想更改actionRadius of action标签。

enter image description here

我试着得到这样的标签:

  UIView *v1 = deleteView.view.subviews[0];
            UIView *v2 = v1.subviews[0];
            UIView *v3 = v2.subviews[0];
    UIView *v4 = v3.subviews[1].subviews[0].subviews[0];
            NSArray *arr = v5.subviews;
    NSArray *arr = v4.subviews;
    NSLog(@"v4:%@,arr:%@",v4,arr);

我得到一个空数组

enter image description here

3 个答案:

答案 0 :(得分:0)

您必须将 masksToBounds 设置为是

  deleteView.view.layer.cornerRadius = 15;
  deleteView.view.layer.masksToBounds = YES;

答案 1 :(得分:0)

简单,只需要2行代码..

deleteView.view.layer.cornerRadius = 100;   deleteView.view.layer.masksToBounds = YES;

答案 2 :(得分:0)

在Sathya Baman的答案之后,添加以下行。背景颜色必须与alertView的当前背景匹配。

alert.view.backgroundColor = .white