高度定制的 AlertView 包,强扩展性
KYAlertView 主要支持 block 块方式的 UIAlertView 扩展,支持原生的 UIAlertView 的四种样式 UIAlertViewStyleLoginAndPasswordInput
,并封装一个高自定义的 UIAlertView,以满足产品提出的不同弹窗需求。支持富文本的 UIAlertView 弹出层。
下载 DEMO 后,将子文件夹 KYAlertViewLib 拖入到项目中,导入头文件 KYNetwork.h
开始使用。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"登录apple成功" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil,nil];
alert.alertViewClickedButtonAtIndexBlock = ^(UIAlertView *alert ,NSUInteger index) {
if (index == 0) {
NSLog(@"知道了");
}
};
[alert show];
如下图所示:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登录 iTunes Store " message:@"请输入您的“[email protected]”的密码" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"好",nil];
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] setPlaceholder:@"请输入6位数字密码"];
alert.alertViewClickedButtonAtIndexBlock = ^(UIAlertView *alert ,NSUInteger index) {
if (index == 0) {
NSLog(@"取消");
}else if (index == 1) {
NSLog(@"好");
}
};
[alert show];
如下图所示:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Apple ID" message:@"[email protected]" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"查看 Apple ID",@"注销",@"iForgot",@"取消",nil];
alert.alertViewClickedButtonAtIndexBlock = ^(UIAlertView *alert ,NSUInteger index) {
if (index == 0) {
NSLog(@"查看 Apple ID");
}else if (index == 1) {
NSLog(@"注销");
}else if (index == 2) {
NSLog(@"iForgot");
}else if (index == 3) {
NSLog(@"取消");
}
};
[alert show];
如下图所示:
[[KYAlertView sharedInstance] showAlertView:@"领取成功"
message:@"哇,中奖了100万,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了"
subBottonTitle:@"分享好友"
cancelButtonTitle:@"立即查看"
handler:^(AlertViewClickBottonType bottonType) {
if (bottonType == AlertViewClickBottonTypeSubBotton) {
NSLog(@"分享好友");
}else if (bottonType == AlertViewClickBottonTypeCancelButton){
NSLog(@"立即查看");
}
}];
如下图所示:
[[KYAlertView sharedInstance] showAlertView:@"领取成功"
message:@"哇,中奖了100万"
subBottonTitle:@"分享好友"
handler:^(AlertViewClickBottonType bottonType) {
if (bottonType == AlertViewClickBottonTypeSubBotton) {
NSLog(@"分享好友");
}
}];
如下图所示:
[[KYAlertView sharedInstance] showAlertView:@"领取失败"
message:@"请联系客服!"
cancelButtonTitle:@"好"
handler:^(AlertViewClickBottonType bottonType) {
if (bottonType == AlertViewClickBottonTypeCancelButton){
NSLog(@"取消");
}
}];
如下图所示:
设置标题的颜色
[alertView setTitleLabelTextColor:[UIColor blackColor]];
设置内容的颜色
[alertView setContentLabelTextColor:[UIColor blueColor]];
设置 AlertView 的背景颜色
[alertView setAlertViewBackgroundColor:[UIColor yellowColor]];
设置 AlertView 的背景图片
[alertView setAlertViewBackgroundImage:[UIImage imageNamed:@"bg_woyeyaoyugao"]];
设置 SubBotton 的背景颜色
[alertView setSubBottonBackgroundColor:[UIColor blackColor]];
设置 SubBotton 的文字颜色
[alertView setSubBottonTitleColor:[UIColor whiteColor]];
设置 SubBotton 的边框颜色
[alertView setSubBottonBorderColor:[UIColor redColor]];
设置 CancelButton 的文字颜色
[alertView setCancelButtonTitleColor:[UIColor orangeColor]];
设置 CancelButto 的背景颜色
[alertView setCancelButtonBackgroundColor:[UIColor whiteColor]];
设置 CancelButton 的边框颜色
[alertView setCancelButtonBorderColor:[UIColor blackColor]];
demo 效果图如下:
KYAlertView *alertView = [KYAlertView sharedInstance];
NSString *messageStr = @"哇,变色了 太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了哇,太好了";
NSMutableAttributedString *attstr = [[NSMutableAttributedString alloc]initWithString:messageStr];
NSRange rangeStr = [messageStr rangeOfString:[NSString stringWithFormat:@"%@",@"变色了"]];
[attstr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:rangeStr];
NSRange range02 = [messageStr rangeOfString:[NSString stringWithFormat:@"%@",@"好"]];
[attstr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20] range:range02];
[alertView setMessageWithAttributedText:attstr];
weibo: http://weibo.com/balenn
QQ 362108564
如果有任何你觉得不对的地方,或有更好的建议,以上联系都可以联系我。 非常感谢!
若它不慎给您帮助,请不吝啬给它点一个强 star,是对它的最好支持,非常感谢!
KYAlertView 在 MIT 协议下获得许可。查看 许可证 文件以获取更多信息。