打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【原】一个基于自动布局的提示框
#import "TBTrustDeveloperWindow.h"#import "TTTAttributedLabel.h"@interface TBTrustDeveloperWindow ()<TTTAttributedLabelDelegate>@end@implementation TBTrustDeveloperWindow{ TTTAttributedLabel *_detailLabel;}- (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self createCustomView]; self.windowLevel = UIWindowLevelStatusBar + 1.f; } return self;}- (void)showWithCompanyId:(NSString *)companyId{ companyId = @"xxxxxx,xxxxxx,Information Technology.Co.Ltd."; NSString *text = [NSString stringWithFormat:_(@"\"iPhone Distribution: %@ \"在此iPhone上尚未受信任。在信任改开发者之前,其企业级应用将不可使用。"),companyId]; NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text]; [mutableAttributedString addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0xff0000) range:[text rangeOfString:companyId]]; [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13.f] range:[text rangeOfString:companyId]]; _detailLabel.text = mutableAttributedString; [self makeKeyAndVisible];}- (void)createCustomView{ UIView *backView = [[UIView alloc]init]; backView.frame = self.bounds; backView.backgroundColor = [UIColor blackColor]; backView.alpha = 0.7; [self addSubview:backView]; UIView *windowView = [[UIView alloc] init]; windowView.backgroundColor = HEXCOLOR(0xf5f5f5); windowView.clipsToBounds = YES; windowView.layer.cornerRadius = 5; [self addSubview:windowView]; UILabel *titleLabel = [[UILabel alloc]init]; titleLabel.textColor = HEXCOLOR(0x2c2b2b); titleLabel.font = [UIFont boldSystemFontOfSize:17.f]; titleLabel.text = _(@"安装好了打不开?"); [windowView addSubview:titleLabel]; UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; [closeButton setImage:[UIImage imageNamed:@"rp_btn_close"] forState:UIControlStateNormal]; closeButton.backgroundColor = [UIColor clearColor]; [closeButton addTarget:self action:@selector(closeButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [windowView addSubview:closeButton]; UIView *contentAreaView = [[UIView alloc] init]; contentAreaView.backgroundColor = HEXCOLOR(0xffffff); [windowView addSubview:contentAreaView]; UILabel *titleLabel2 = [[UILabel alloc] init]; titleLabel2.font = [UIFont boldSystemFontOfSize:15]; titleLabel2.textColor = HEXCOLOR(0x000000); titleLabel2.textAlignment = NSTextAlignmentCenter; titleLabel2.text = _(@"未受信任的企业级开发者"); [contentAreaView addSubview:titleLabel2]; _detailLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; _detailLabel.numberOfLines = 0; // 重要,设置为0,表示行数自动计算,即高度自动计算 _detailLabel.textAlignment = NSTextAlignmentCenter; _detailLabel.minimumLineHeight = 18; _detailLabel.font = [UIFont systemFontOfSize:13.f]; _detailLabel.textColor = HEXCOLOR(0x000000); _detailLabel.backgroundColor = [UIColor clearColor]; _detailLabel.delegate = self;// [contentLabel2 addLinkToURL:[NSURL URLWithString:@"http://id.tongbu.com"] withRange:[text rangeOfString:@"http://id.tongbu.com"]]; [contentAreaView addSubview:_detailLabel]; UILabel *contentLabel = [[UILabel alloc] init]; contentLabel.backgroundColor = [UIColor clearColor]; contentLabel.text = _(@"进入系统【设置】->【通用】->【描述文件】,找到并信任上述红色的企业开发者。"); contentLabel.font = [UIFont systemFontOfSize:12.f]; contentLabel.textColor = HEXCOLOR(0x000000); contentLabel.numberOfLines = 0; // 重要,设置为0,表示行数自动计算,即高度自动计算 [windowView addSubview:contentLabel]; UIView *lineView = [[UIView alloc] init]; lineView.backgroundColor = HEXCOLOR(0xdbdbdb); [windowView addSubview:lineView]; UIButton *openSettingButton = [UIButton buttonWithType:UIButtonTypeCustom]; [openSettingButton setTitle:_(@"进入描述文件") forState:UIControlStateNormal]; openSettingButton.backgroundColor = HEXCOLOR(0x0f95d8); openSettingButton.layer.cornerRadius = 5; [openSettingButton setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal]; openSettingButton.clipsToBounds = YES; [openSettingButton addTarget:self action:@selector(openSettingButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [windowView addSubview:openSettingButton]; // 以下所有约束都是相对于最上面的控件进行排列,遇到label则不限制高度,层层向下,从内向外 [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(windowView).offset(13); make.centerX.mas_equalTo(windowView); }]; [closeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(titleLabel); make.size.mas_equalTo(CGSizeMake(25, 25)); make.right.mas_equalTo(windowView).offset(-12); }]; // 自动计算高度 [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(contentAreaView).offset(12); make.left.mas_equalTo(contentAreaView).offset(10); make.right.mas_equalTo(contentAreaView).offset(-10); }]; // 自动计算高度 [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(titleLabel2.mas_bottom).offset(10); make.left.mas_equalTo(contentAreaView).offset(20); make.right.mas_equalTo(contentAreaView).offset(-20); }]; [contentAreaView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(windowView).offset(46); make.left.mas_equalTo(windowView).offset(11); make.right.mas_equalTo(windowView).offset(-11); make.bottom.mas_equalTo(_detailLabel.mas_bottom).offset(15); }]; // 自动计算高度 [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(contentAreaView.mas_bottom).offset(14); make.left.mas_equalTo(windowView).offset(11); make.right.mas_equalTo(windowView).offset(-11); }]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(1.f); make.width.mas_equalTo(windowView); make.left.mas_equalTo(windowView); make.top.mas_equalTo(contentLabel.mas_bottom).offset(16); }]; [openSettingButton mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(lineView.mas_bottom).offset(12); make.left.mas_equalTo(windowView).offset(10); make.right.mas_equalTo(windowView).offset(-10); make.height.mas_equalTo(35); }]; [windowView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(self.frame.size.width - 58); make.center.mas_equalTo(self); make.bottom.mas_equalTo(openSettingButton.mas_bottom).offset(12); }];}- (void)closeButtonClick:(UIButton *)sender{ self.hidden = YES; if (_tbDelegate && [_tbDelegate respondsToSelector:@selector(trustDeveloperWindowDidHiden)]) { [_tbDelegate trustDeveloperWindowDidHiden]; }}- (void)openSettingButtonClick:(UIButton *)sender{ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=ManagedConfigurationList"]]; [self closeButtonClick:nil];}#pragma mark - TTTAttributedLabelDelegate- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url{}@end
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
iOS文本输入过滤 emoji 表情符号
UITextView的动态适应高度处理
iOS中使用ARC的注意事项
IOS 中的XML解析
UITextField的总结
加速计与陀螺仪
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服