github地址:https://github.com/HannahZheng/HHAlertTest
因項(xiàng)目所需饺谬,簡(jiǎn)單定制了一個(gè)AlertView,只支持圖一和圖二的樣式钠署。
需要依賴(lài)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 = @"只有升級(jí)成正式店主可以提現(xiàn)";
_alertView.detailLabel.textAlignment = NSTextAlignmentCenter;
_alertView.detailLabel.font = [UIFont boldSystemFontOfSize:15];
[_alertView addBtnWithType:HHAlertButtonTypeDefault btnTitle:@"去升級(jí)" block:^{
//這里可以寫(xiě)相關(guān)的操作
}];
[_alertView addBtnWithType:HHAlertButtonTypeCancle btnTitle:@"再等等" block:nil];
}
return _alertView;
}
如果項(xiàng)目適配的系統(tǒng)最低是iOS 9朝群,可采用修改UIAlertController按鈕顏色和字號(hào)來(lái)實(shí)現(xiàn)
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"只有升級(jí)成正式店主可以提現(xiàn)" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sureA = [UIAlertAction actionWithTitle:@"去升級(jí)" 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
如果需要對(duì)title,detail顏色毕源,字號(hào)岸更,文本位置修改,參考:
//修改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:@"提示內(nèi)容"];
[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"];