修改UIAlertAction 的文字颜色
来源:互联网 发布:单农为什么淘宝没有 编辑:程序博客网 时间:2024/05/16 08:53
func setTextColor(color: UIColor) {
var count: uint = 0;
let ivars = class_copyIvarList(UIAlertAction.classForCoder(), &count)
for i in 0 ..< Int(count) {
let ivar = ivars[i]
let name = ivar_getName(ivar)
if let varName = String.fromCString(name) {
if varName == "_titleTextColor" {
self.setValue(color, forKey: "titleTextColor")
}
}
}
}
}
extension UIAlertController {
func setTitleColor(color: UIColor) {
var count: uint = 0;
let ivars = class_copyIvarList(UIAlertAction.classForCoder(), &count)
for i in 0 ..< Int(count) {
let ivar = ivars[i]
let name = ivar_getName(ivar)
if let varName = String.fromCString(name) {
if varName == "_attributedTitle" {
self.setValue(color, forKey: "attributedTitle")
}
}
}
}
func setMessageColor(color: UIColor) {
var count: uint = 0;
let ivars = class_copyIvarList(UIAlertAction.classForCoder(), &count)
for i in 0 ..< Int(count) {
let ivar = ivars[i]
let name = ivar_getName(ivar)
if let varName = String.fromCString(name) {
if varName == "_attributedMessage" {
self.setValue(color, forKey: "attributedMessage")
}
}
}
}
func show() {
let alert = Alert(alertController: self)
Alert.showViewCtrl(self)
AlertManager.defaultManager().addAlert(alert)
}
}
用法:
- (void)alertStartDownloadOnWWAN:(void(^)())blockDownload {
if (self.netWorkState.netWorkStatus != NetworkViaWiFi && self.netWorkState.netWorkStatus !=NetworkNone) {
NSString *message =NSLocalizedString(@"2G/3G/4G下载将消耗您的数据流量,是否继续?",nil);
NSString *cancel =NSLocalizedString(@"继续下载",nil);
UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@""message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionDownload = [UIAlertActionactionWithTitle:cancel style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *_Nonnull action) {
if (blockDownload !=nil) {
blockDownload();
}
}];
[actionDownload setTextColor:[UIColorblueColor]];
UIAlertAction *actionNotDownload = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *_Nonnull action) {
}];
[actionNotDownload setTextColor:[UIColorblueColor]];
[alertController addAction:actionDownload];
[alertController addAction:actionNotDownload];
[alertController show];
} elseif (blockDownload != nil){
blockDownload();
}
}
- 修改UIAlertAction 的文字颜色
- 修改UIAlertAction颜色
- 更改UIAlertAction的字体颜色
- 修改状态栏文字的颜色
- 如何设置UIAlertAction提示信息的部分字体的颜色
- 修改控制台的文字和背景颜色
- iOS怎么修改section的文字颜色
- 修改 text-field 的 placeholder 文字颜色
- textField.placeholder的文字颜色修改
- 如何修改 placeholder 的文字颜色?
- 修改FloatingActionButton的title的文字颜色及背景颜色
- backBarButtonItem 颜色/文字修改
- UIActionSheet修改文字颜色
- 修改状态栏文字颜色?
- 修改状态栏文字颜色
- UIAlertAction的用法
- UIAlertAction
- 在Myeclipse中提示的文字的背景颜色修改
- 升级ubuntu中的gcc和g++版本
- 《Linux内核设计与实现》--系统调用
- jsp中使用c:import 传递中文参数乱码
- #278 – 允许Image只能变小或者只能变大(Allow an Image to Get Bigger, But Not Smaller (or Vice Versa))
- c# 使用定时器Timer
- 修改UIAlertAction 的文字颜色
- mysql数据库delete数据时不支持表别名
- Linux题目(二)
- TensorFlow教程06:MNIST的CNN实现——源码和运行结果
- 雅虎团队经验:网站页面性能优化的 34条(二)
- 设计模式 ( 十八 ) 策略模式Strategy(对象行为型)
- 解决:Unable to connect to repository https://dl-ssl.google.com/android/eclipse/site.xml
- 无限级CSS树形菜单 Ver2.0
- new与malloc的区别,以及内存分配浅析