UIPopoverPresentationController 对话框弹窗控件

image.png
    /// Description
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor];
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 40, 40)];
    btn.backgroundColor = [UIColor redColor];
    
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    self.aimBtn = btn;
}

- (void)click{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 25, 120, 100)];
    label.textColor = [UIColor blackColor];
    label.layer.borderWidth = 2.0;
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = @"担保好232323\n订单编号32323\n订单号33333\n保单号nbaohano";
    label.numberOfLines = 0;
    label.textColor = [UIColor blackColor];
    [self.view addSubview:label];
    self.aimlab = label;
    [self.aimlab sizeToFit];
    
    UIViewController *testVC = [[UIViewController alloc] init];
    [testVC.view addSubview:label];
    NSLog(@"%@",NSStringFromCGRect(label.frame));
       testVC.preferredContentSize = CGSizeMake(self.aimlab.bounds.size.width + 10, self.aimlab.bounds.size.height + 25) ;
       testVC.modalPresentationStyle = UIModalPresentationPopover;
       testVC.popoverPresentationController.delegate = self;
       testVC.popoverPresentationController.sourceView = self.aimBtn;
       testVC.popoverPresentationController.sourceRect = self.aimBtn.bounds;
       testVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
       testVC.popoverPresentationController.backgroundColor = [UIColor redColor];
       testVC.popoverPresentationController.canOverlapSourceViewRect = NO;
    testVC.popoverPresentationController.popoverLayoutMargins = UIEdgeInsetsMake(20, 20, 20, 20);
       [self presentViewController:testVC animated:YES completion:^{
       }];
}
#pragma mark - <UIPopoverPresentationControllerDelegate>
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationNone;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容