最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
iOS 自定义系统的UIAlertView调整Alert字体
时间:2013-10-24 编辑:简简单单 来源:一聚教程网
iOS中UIAlertView很少有单独定制的需要,一般采用系统样式即可,但是有时候一些特殊的需求(比如:UIAlertView的字体,字体大小,字体对齐方式变化等)就不得不需要单独对UIAlertView进行定制了。
定制的方法也很简单,在viewController的Delegate实现方法willPresentAlertView中遍历UIAlertView下面所有subview,找到对应的UILabel再对UILabel的属性进行修改即可。操作基本一致。
参考代码;
代码如下 | 复制代码 |
- (void)willPresentAlertView:(UIAlertView *)alertView { // 遍历 UIAlertView 所包含的所有控件 for (UIView *tempView in alertView.subviews) { if ([tempView isKindOfClass:[UILabel class]]) { // 当该控件为一个 UILabel 时 UILabel *tempLabel = (UILabel *) tempView; if ([tempLabel.text isEqualToString:alertView.message]) { // 调整对齐方式 tempLabel.textAlignment = UITextAlignmentLeft; // 调整字体大小 [tempLabel setFont:[UIFont systemFontOfSize:15.0]]; } } } } |
以上代码不会出现使用了私有API的问题
相关文章
- ps如何添加自定义形状 07-02
- ppt自定义尺寸 07-02
- Tiki如何自定义添加个性贴 06-18
- ps图案和画笔预设怎么自定义 有什么作用 06-14
- AI参考线如何自定义颜色 06-14
- Vue自定义指令拖拽功能示例 04-13