您好,欢迎来到知库网。
搜索
您的当前位置:首页AlertView的简单定制

AlertView的简单定制

来源:知库网
图一.png 图二.png

需要依赖Masonry布局。
使用方法如下:

- (IBAction)show:(id)sender {
    
    [self.alertView show];
}



- (HHAlertView *)alertView{
    if (_alertView == nil) {
        _alertView = [[HHAlertView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_alertView];
        _alertView.message = @"只有升级成正式店主可以提现";
        _alertView.detailLabel.textAlignment = NSTextAlignmentCenter;
        _alertView.detailLabel.font = [UIFont boldSystemFontOfSize:15];

        [_alertView addBtnWithType:HHAlertButtonTypeDefault btnTitle:@"去升级" block:^{
            //这里可以写相关的操作
        }];
        [_alertView addBtnWithType:HHAlertButtonTypeCancle btnTitle:@"再等等" block:nil];
    }
    return _alertView;
}

如果项目适配的系统最低是iOS 9,可采用修改UIAlertController按钮颜色和字号来实现

 UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"只有升级成正式店主可以提现" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureA = [UIAlertAction actionWithTitle:@"去升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self goToMememberExclusiveVC];
    }];
    [sureA setValue:HHColor(229, 0, 17) forKey:@"titleTextColor"];
    UIAlertAction *cancleA = [UIAlertAction actionWithTitle:@"再等等" style:UIAlertActionStyleDefault handler:nil];
    [cancleA setValue:HHColor(51, 51, 51) forKey:@"titleTextColor"];

    [alertVC addAction:cancleA];
    [alertVC addAction:sureA];
    [self.withVC presentViewController:alertVC animated:YES completion

如果需要对title,detail颜色,字号,文本位置修改,参考:

//修改title
  NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
  [alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
  [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
[alertVC setValue:alertControllerStr forKey:@"attributedTitle"];

  //修改message
  NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"提示内容"];
  [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 4)];
  [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 4)];
   [alertVC setValue:alertControllerMessageStr forKey:@"attributedMessage"];

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务