简体   繁体   English

如何自定义UIAlertView消息字体?

[英]how to customise UIAlertView Message Font?

Simply I have a button that popUp a UIAlertView view 简单地说,我有一个弹出UIAlertView视图的按钮

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"u clicked me !!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
 [alert show];
 [alert release];

I want to change the font and the size of the message also the color of the UIAlertView? 我想更改消息的字体和大小以及UIAlertView的颜色?

is there a simple way to do that? 有一个简单的方法吗?

I hear of lots of people subclassing UIAlertView, but then I read this comment on Apple's UIAlertView Class Reference page : 我听说有很多人继承UIAlertView,但后来我在Apple的UIAlertView类参考页面上阅读了这条评论:

Subclassing Notes 子类注释

The UIAlertView class is intended to be used as-is and does not support subclassing. UIAlertView类旨在按原样使用,不支持子类化。 The view hierarchy for this class is private and must not be modified. 此类的视图层次结构是私有的,不得修改。

ie people should not be attempting to modify the elements or behavior of UIAlertView. 即人们不应该试图修改UIAlertView的元素或行为。 It's likely that behavior can change in later versions of iOS (eg iOS 6 or iOS 5.3 or whatever), breaking their various modifications to UIAlertView. 在iOS的更高版本(例如iOS 6或iOS 5.3或其他版本)中,行为可能会发生变化,从而打破了对UIAlertView的各种修改。

Anyways, to answer your question: why not try creating your own UIView that you can add as UIAlertView-like subview on top of any of your views? 无论如何,要回答你的问题:为什么不尝试创建你自己的UIView,你可以在你的任何视图之上添加类似UIAlertView的子视图? That way, you'd have easy control over both the background color and the label fonts and everything. 这样,您可以轻松控制背景颜色和标签字体以及所有内容。

Don't think there's easy way to change the background colour. 不要以为有简单的方法来改变背景颜色。 If you only want to change the font size, please have a look at this post by Himanshu Sharma . 如果您只想更改字体大小,请查看Himanshu Sharma的这篇文章

I have issue with Appirater for iPhone in Landscape mode and used the code to adjust the font size and it works for me. 我在横向模式下遇到了Appirater for iPhone的问题,并使用代码来调整字体大小,它对我有用。 Hope this helps. 希望这可以帮助。 Cheers 干杯

这是一个迟到的答案,但你可以尝试GRAlertView,我觉得非常好: GRAlertView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM