当前位置:编程学习 > wap >>

改变警告框中信息的对齐方式

默认情况下,警告框中的文本都是居中对齐的,现在我想改为左对齐,可以做的到吗? app --------------------编程问答-------------------- http://fenglepai.com/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9uialertview%E4%B8%AD%E6%A0%87%E9%A2%98%E5%92%8C%E4%BF%A1%E6%81%AF%E7%9A%84%E5%AF%B9%E9%BD%90%E6%96%B9%E5%BC%8F%E5%91%A2%EF%BC%9F.html
这个实现并不复杂,在消息框即将弹出时,遍历所有消息框对象,将其文本对齐属性修改为 UITextAlignmentLeft即可。你所要做的就是在-(void)willPresentAlertView:(UIAlertView *)alertView中按照自己的需要修改或添加即可, 比如你现在需要将消息文本左对齐,下面的代码即可实现:
123456789 -(void) willPresentAlertView:(UIAlertView *)alertView{      for( UIView * view in alertView.subviews ){            if( [view isKindOfClass:[UILabel class]] )            {                  UILabel* label = (UILabel*) view;                  label.textAlignment=UITextAlignmentLeft;            }      }} --------------------编程问答-------------------- 1 如果你的应用不需要上架,你可以使用UIAlertView private方法,
- (void) addTextFieldWithValue:(NSString *) value label:(NSString *) label;
- (void) addTextFieldAtIndex:(NSUInteger) index;


2 如果你的应用支持5.0+
则可以使用下面的方法来组合你要的效果
// Alert view style - defaults to UIAlertViewStyleDefault
@property(nonatomic,assign) UIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(5_0);

/* Retrieve a text field at an index - raises NSRangeException when textFieldIndex is out-of-bounds. 
   The field at index 0 will be the first text field (the single field or the login field), the field at index 1 will be the password field. */
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
--------------------编程问答-------------------- 警告框框都是我自己写的,基本上不会用系统自己带的,所以什么文本图片按钮控件的对齐方式都是我自己说了算。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,