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;
}