UIAlertView左对齐及设置用户登录对话框
2012-10-10 13:35
288 查看
UIAlertView左对齐及设置用户登录对话框
iPhone SDK提供 UIAlertView用以显示消息框, 默认的消息框很简单,只需要提供title和message以及button按钮即可, 而且默认情况下素有的text是居中对齐的。 那如果需要将文本向左对齐或者添加其他控件比如输入框时该怎么办呢? 不用担心, iPhone SDK还是很灵活的, 有很多delegate消息供调用程序使用。 所要做的就是在
- (void)willPresentAlertView:(UIAlertView *)alertView
中按照自己的需要修改或添加即可, 比如需要将消息文本左对齐,下面的代码即可实现
- (void)willPresentAlertView:(UIAlertView *)alertView{
for( UIView * view in alertView.subviews )
{ if( [view isKindOfClass:[UILabel class]] )
{ UILabel* label = (UILabel*) view;
label.textAlignment = UITextAlignmentLeft; }
}
}这段代码很简单, 就是在消息框即将弹出时,遍历所有消息框对象,将其文本对齐属性修改为UITextAlignmentLeft即可。
添加其他部件也如出一辙, 如下代码添加两个UITextField
- (void)willPresentAlertView:(UIAlertView *)alertView{
CGRect frame = alertView.frame;
if( alertView==twitterAlertView )
{ frame.origin.y -= 120;
frame.size.height += 80;
alertView.frame = frame;
for( UIView * view in alertView.subviews )
if( ![view isKindOfClass:[UILabel class]] )
{ CGRect btnFrame = view.frame;
btnFrame.origin.y += 70;
view.frame = btnFrame;
}
}
UITextField* accoutName = [[HelperClass createTextField] autorelease];//这里创建一个UITextField对象
UITextField* accoutPassword = [[HelperClass createTextField] autorelease];//这里创建一个UITextField对象
accoutName.frame = CGRectMake( 10, 40,frame.size.width - 20, 30 );
accoutPassword.frame = CGRectMake( 10, 80,frame.size.width -20, 30 );
accoutName.placeholder = @"Account Name";
accoutPassword.placeholder = @"Password";
accoutPassword.secureTextEntry = YES;
[alertView addSubview:accoutPassword];
[alertView addSubview:accoutName]; }}显示将消息框固有的button和label移位, 不然添加的text field会将其遮盖住。 然后添加需要的部件到相应的位置即可。
对于UIActionSheet其实也是一样的, 在
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
中做同样的处理一样可以得到自己想要的界面。
iPhone SDK提供 UIAlertView用以显示消息框, 默认的消息框很简单,只需要提供title和message以及button按钮即可, 而且默认情况下素有的text是居中对齐的。 那如果需要将文本向左对齐或者添加其他控件比如输入框时该怎么办呢? 不用担心, iPhone SDK还是很灵活的, 有很多delegate消息供调用程序使用。 所要做的就是在
- (void)willPresentAlertView:(UIAlertView *)alertView
中按照自己的需要修改或添加即可, 比如需要将消息文本左对齐,下面的代码即可实现
- (void)willPresentAlertView:(UIAlertView *)alertView{
for( UIView * view in alertView.subviews )
{ if( [view isKindOfClass:[UILabel class]] )
{ UILabel* label = (UILabel*) view;
label.textAlignment = UITextAlignmentLeft; }
}
}这段代码很简单, 就是在消息框即将弹出时,遍历所有消息框对象,将其文本对齐属性修改为UITextAlignmentLeft即可。
添加其他部件也如出一辙, 如下代码添加两个UITextField
- (void)willPresentAlertView:(UIAlertView *)alertView{
CGRect frame = alertView.frame;
if( alertView==twitterAlertView )
{ frame.origin.y -= 120;
frame.size.height += 80;
alertView.frame = frame;
for( UIView * view in alertView.subviews )
if( ![view isKindOfClass:[UILabel class]] )
{ CGRect btnFrame = view.frame;
btnFrame.origin.y += 70;
view.frame = btnFrame;
}
}
UITextField* accoutName = [[HelperClass createTextField] autorelease];//这里创建一个UITextField对象
UITextField* accoutPassword = [[HelperClass createTextField] autorelease];//这里创建一个UITextField对象
accoutName.frame = CGRectMake( 10, 40,frame.size.width - 20, 30 );
accoutPassword.frame = CGRectMake( 10, 80,frame.size.width -20, 30 );
accoutName.placeholder = @"Account Name";
accoutPassword.placeholder = @"Password";
accoutPassword.secureTextEntry = YES;
[alertView addSubview:accoutPassword];
[alertView addSubview:accoutName]; }}显示将消息框固有的button和label移位, 不然添加的text field会将其遮盖住。 然后添加需要的部件到相应的位置即可。
对于UIActionSheet其实也是一样的, 在
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
中做同样的处理一样可以得到自己想要的界面。
相关文章推荐
- IOS开发:UIAlertView设置文字左对齐
- UIAlertView设置文字左对齐
- 设置UIAlertView文字对齐
- (iPhone/iPad开发)设置UIAlertView中message字段左对齐
- iOS6.0\iOS7.0\iOS8.0的UIAlertView message 文字对齐设置
- 【原创】Windows server 2003 下设置单用户登录远程桌面连接
- 在REDHAT6.X中设置VNC多用户登录
- 通过Powershell, C#, CMD and VBScript等设置 用户 作为服务登录
- LFS中用户登录脚本、xinit与xdm启动应用程序(输入法)的快速设置
- Ubuntu设置root用户登录
- Ubuntu12.04 root 用户登录设置
- Ubuntu12.04 root用户登录设置
- UIAlertView消息文本左对齐操作
- Yii controller控制器下设置对于用户没有登录的请求跳转至指定URL的方法
- Ubuntu 12.04 root用户登录设置
- Linux 设置root用户登录
- Ubuntu14.04设置开机root用户登录
- ubuntu的root用户登录登出及密码设置
- java web相同用户重复登陆,即用户唯一登录,后登陆挤掉先登录的,设置限制用户同时登陆人数