如何编辑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) {}]; 

现在我想要我的“注销”字体大小为22,绿色,半色的文本。

您可以使用更新文字颜色

  UIAlertAction *myGoalAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"My Title", @"My Title") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { }]; [myGoalAction setValue:[UIColor greenColor] forKey:@"titleTextColor"]; 

没有有效的方法来更新字体大小。我会build议你使用标准的字体大小。

UIAlertAction标题标签是私有variables,不能直接访问。 标签进入3级私人视图层次结构。 显示更大的字体注销行动是有意义的应用程序。

有很多开源解决schemeavailable.I将build议尝试这一点

改变颜色很简单。

您可以更改底层视图的tintColor,但由于iOS 9( https://openradar.appspot.com/22209332 )中引入的已知错误,tintColor被应用程序窗口的tintColor覆盖。

查看我的完整答案: 如何更改UIAlertController的色调颜色

您不应该更改UIAlertController字体。 但是它仍然可以完成,看到这个答案

尝试这个:

 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Do you wish to logout?" message:@"abcd" preferredStyle:UIAlertControllerStyleActionSheet]; NSMutableAttributedString *xyz = [[NSMutableAttributedString alloc] initWithString:@"pqrs"]; [xyz addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0] range:NSMakeRange(20, 15)]; [alert setValue:xyz forKey:@"attributedTitle"]; UIAlertAction *logout = [UIAlertAction actionWithTitle:@"logout" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ //your code for handling this }]; UIImage *Image = [UIImage imageNamed:@"yourImage"]; [logout setValue:accessoryImage forKey:@"image"]; 

使用NSMutableAttributedString设置字体大小和颜色,使用下面的代码,

 UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"Do you wish to logout?" message:@"" preferredStyle:UIAlertControllerStyleAlert]; NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Do you wish to logout?"]; [hogan addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:50.0] range:NSMakeRange(24, 11)]; [hogan addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,35)]; [controller setValue:hogan forKey:@"attributedTitle"]; UIAlertAction *logOut = [UIAlertAction actionWithTitle:@"Log Out" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}]; 

希望它有帮助