nao*_*omi 15 objective-c popup ios uialertaction
如何编辑UIAlertAction文字大小和颜色?我已经采取了UIAlertController如何编辑大小的方法.这个我smy代码
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Do you wish to logout?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *logOut = [UIAlertAction actionWithTitle:@"Log Out" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];
Run Code Online (Sandbox Code Playgroud)
现在我想要我的'Log Out'文本,字体大小为22,绿色和semibold.
kau*_*hal 39
您可以使用更新文本颜色
UIAlertAction *myGoalAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"My Title", @"My Title")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
}];
[myGoalAction setValue:[UIColor greenColor] forKey:@"titleTextColor"];
Run Code Online (Sandbox Code Playgroud)
没有有效的方法来更新字体大小.我建议您使用标准字体大小.
UIAlertAction标题标签是私有变量,无法直接访问.标签位于3级私有视图层次结构中.显示更大字体的注销操作对app有意义.
有很多开源解决方案可供使用.我建议尝试这个
我写了一个扩展
extension UIAlertController{
open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
for i in self.actions {
let attributedText = NSAttributedString(string: i.title ?? "", attributes: [NSAttributedString.Key.font : UIFont(name: "SFProText-Semibold", size: 20.0)!])
guard let label = (i.value(forKey: "__representer") as AnyObject).value(forKey: "label") as? UILabel else { return }
label.attributedText = attributedText
}
}
}
Run Code Online (Sandbox Code Playgroud)
改变颜色非常简单。
您可以只更改基础视图的tintColor,但是,由于iOS 9 ( https://openradar.appspot.com/22209332 )中引入的已知错误,tintColor 被应用程序窗口的tintColor 覆盖。
请参阅我的完整答案:如何更改 UIAlertController 的色调颜色
你不应该改变UIAlertController字体。不过仍然可以做到,请参阅这个答案
| 归档时间: |
|
| 查看次数: |
16834 次 |
| 最近记录: |