iOS自定义弹窗(UIView)

来源:互联网 发布:pc mac os x 编辑:程序博客网 时间:2024/05/18 03:54

iOS自定义弹窗(UIView)

效果:



解决:

1. 先放一层 黑色 50%透明度的背景 , 再放弹窗,再在弹窗上放置自定义。

    //================================================    //弹窗    //================================================    //中灰背景    UIView *alertBackView = [[UIView alloc] initWithFrame:parentView.frame];    alertBackView.backgroundColor = [UIColor colorWithHex:0x000000 alpha:0.5];    [parentView addSubview:alertBackView];    //弹窗    UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake((parentView.width - kAlertViewWidth) / 2, (parentView.height - kAlertViewHeight) / 2, kAlertViewWidth, kAlertViewHeight)];    alertView.backgroundColor = [UIColor whiteColor];    alertView.layer.cornerRadius = 0.02 * kAlertViewWidth;    [alertBackView addSubview:alertView];    //文字       UILabel *labelAlert = [[UILabel alloc] init];    labelAlert.lineBreakMode = NSLineBreakByWordWrapping;    labelAlert.numberOfLines = 0;    labelAlert.text = @"感谢注册Hi-service平台,点击左侧\n工具箱中的“邀请同事”按钮可以快\n速地邀请同事加入。";    labelAlert.font = [UIFont systemFontOfSize:kContentScaleFactor(24)];    labelAlert.textColor = [UIColor colorWithHex:0x464646 alpha:1];    [labelAlert sizeToFit];    labelAlert.frame = CGRectMake(kContentScaleFactor(50), kContentScaleFactor(60), labelAlert.width, labelAlert.height);    [alertView addSubview:labelAlert];    //按钮    UIButton *AlertButton = [[UIButton alloc] initWithFrame:CGRectMake(kContentScaleFactor(62), kContentScaleFactor(60+50)+labelAlert.height, kContentScaleFactor(356), kContentScaleFactor(66))];    [AlertButton setAttributedTitle:[[NSAttributedString alloc] initWithString:@"邀请同事"                                                                   attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],                                                                                NSFontAttributeName:[UIFont systemFontOfSize:kContentScaleFactor(28)]}]                           forState:UIControlStateNormal];    AlertButton.backgroundColor = kAPPThemeColor;    AlertButton.layer.cornerRadius = 0.02 * kContentScaleFactor(356);    [alertView addSubview:AlertButton];


添加单击手势事件,removeFromSuperView关闭弹窗。


0 0
原创粉丝点击