PopUp 的库太多了,你可以根据需要添加。
最好的是 -
1.https://github.com/jmascia/KLCPopup
还有一个庞大的开源 iOS 库库
2.https://www.cocoacontrols.com/search?q=popup
试一试,希望对你有帮助。
以编程方式更新
添加这些属性:-
@property (strong, nonatomic) UIView *container;
@property (strong, nonatomic) UIView *pop;
@synthesize 它们。
设置带有阴影效果的弹出窗口:-
-(void)setViewPop{
_container = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubview:_container];
//self.backgroundDimmingView = [self buildBackgroundDimmingView];
//[self.container addSubview:self.backgroundDimmingView];
pop = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height , self.view.frame.size.width-80, self.view.frame.size.height/1.5-40 )];
pop.backgroundColor = [UIColor orangeColor];
pop.layer.cornerRadius = 10;
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:pop.bounds];
pop.layer.masksToBounds = NO;
pop.layer.shadowRadius = 5;
pop.layer.shadowColor = [UIColor whiteColor].CGColor;
pop.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
pop.layer.shadowOpacity = 0.5f;
pop.layer.shadowPath = shadowPath.CGPath;
[self.container addSubview:pop];
[self setUpPop];
pop.center = self.container.center;
}
弹出视图的内容;-
-(void)setUpPop{
self.pop.frame = CGRectMake(0, 0, self.view.frame.size.width-80, self.view.frame.size.height/1.5-40 );
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(90, 10, 100, 20)];
title.textColor = [UIColor whiteColor];
title.textAlignment = NSTextAlignmentCenter;
title.text = @"Choose Date";
[self.pop addSubview:title];
UIButton *cancelbutton = [[UIButton alloc] initWithFrame:CGRectMake(0,self.pop.frame.size.height-40, self.pop.frame.size.width/2, 40)];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cancelbutton.bounds byRoundingCorners:( UIRectCornerBottomLeft) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
cancelbutton.layer.mask = maskLayer;
cancelbutton.backgroundColor = [UIColor lightGrayColor];
[cancelbutton setTitle:@"Cancel" forState:UIControlStateNormal];
[cancelbutton addTarget:self
action:@selector(cancelbuttonTapped:)
forControlEvents:UIControlEventTouchUpInside];
[pop addSubview:cancelbutton];
UIButton *confirmbutton = [[UIButton alloc] initWithFrame:CGRectMake(140, self.pop.frame.size.height-40,self.pop.frame.size.width/2, 30)];
UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:confirmbutton.bounds byRoundingCorners:( UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
maskLayer1.frame = self.view.bounds;
maskLayer1.path = maskPath1.CGPath;
confirmbutton.layer.mask = maskLayer1;
confirmbutton.backgroundColor = [UIColor orangeColor];
confirmbutton.alpha=0.8f;
[confirmbutton setTitle:@"set Date" forState:UIControlStateNormal];
[pop addSubview:confirmbutton];
}
这是显示视图的动画;-
- (void)showPopUp{
_container.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.5f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:3.0f options:UIViewAnimationOptionAllowAnimatedContent animations:^{
_container.transform = CGAffineTransformIdentity;
[self setViewPop];
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
}
在按钮单击或文本字段上调用 -(void)showPopUp 方法。根据您的需要。