IOS学习之路二十二(UIAlertView获得文本框内容及添加北京图片)
2013-09-10 19:28
781 查看
今天写项目要用到警告框带输入框的,于是就自己做了个小demo.
效果图大体如下:
![](https://img-blog.csdn.net/20130910191951296?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2lsZGNhdGxlbGU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
下面简单介绍一下UIAlertView
alertViewStyle属性有以下三种选项:
下面分别来看看这三种属性的效果:
![](http://isaced-img.stor.sinaapp.com/original/2e1a29bb07dfe38e31a7c9243e9c1e19.png)
![](http://isaced-img.stor.sinaapp.com/original/ac43d2c6d98bb9731bf4b9c37c44b19e.png)
(UIAlertViewStylePlainTextInput) (UIAlertViewStyleSecureTextInput)
![](http://isaced-img.stor.sinaapp.com/original/89a2d541c478e92c1e95a4ed9e6ad639.png)
(UIAlertViewStyleLoginAndPasswordInput)
下面附上自己写的部分关键代码:
#pragma mark 弹出菜单
- (IBAction)showMenu:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"修改Webservice请求地址"
message:@"请输入地址:(http://192.168.6.12)"
delegate:self cancelButtonTitle:@"确定"
otherButtonTitles:@"取消", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
//背景View
UIView *additonBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, alertView.frame.size.width-30, alertView.frame.size.height-20)];
additonBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bag3.jpg"]]; //添加背景图片
[alertView insertSubview:additonBackgroundView atIndex:1];
}
#pragma mark 获得输入框里的值
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"确定"]){
UITextField *tf=[alertView textFieldAtIndex:0];//获得输入框
NSString * requestedURL=tf.text;//获得值
}
}
转载请注明:
新浪微博:http://weibo.com/u/3202802157
效果图大体如下:
下面简单介绍一下UIAlertView
alertViewStyle属性有以下三种选项:
UIAlertViewStylePlainTextInput | 添加一个普通输入框 |
UIAlertViewStyleSecureTextInput | 密码输入框 |
UIAlertViewStyleLoginAndPasswordInput | 普通输入框加密码输入框 |
下面分别来看看这三种属性的效果:
![](http://isaced-img.stor.sinaapp.com/original/2e1a29bb07dfe38e31a7c9243e9c1e19.png)
![](http://isaced-img.stor.sinaapp.com/original/ac43d2c6d98bb9731bf4b9c37c44b19e.png)
(UIAlertViewStylePlainTextInput) (UIAlertViewStyleSecureTextInput)
![](http://isaced-img.stor.sinaapp.com/original/89a2d541c478e92c1e95a4ed9e6ad639.png)
(UIAlertViewStyleLoginAndPasswordInput)
下面附上自己写的部分关键代码:
#pragma mark 弹出菜单
- (IBAction)showMenu:(id)sender {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"修改Webservice请求地址"
message:@"请输入地址:(http://192.168.6.12)"
delegate:self cancelButtonTitle:@"确定"
otherButtonTitles:@"取消", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
//背景View
UIView *additonBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, alertView.frame.size.width-30, alertView.frame.size.height-20)];
additonBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bag3.jpg"]]; //添加背景图片
[alertView insertSubview:additonBackgroundView atIndex:1];
}
#pragma mark 获得输入框里的值
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"确定"]){
UITextField *tf=[alertView textFieldAtIndex:0];//获得输入框
NSString * requestedURL=tf.text;//获得值
}
}
转载请注明:
新浪微博:http://weibo.com/u/3202802157
相关文章推荐
- IOS学习之路二十二(UIAlertView获得文本框内容及添加北京图片)
- IOS学习之动态添加Button和监听UIAlertView按钮
- IOS学习之路二十四(UIImageView 加载gif图片)
- IOS学习之动态添加Button和监听UIAlertView按钮
- IOS学习之路二十四(UIImageView 加载gif图片)
- 【学习ios之路:UI系列】UIAlertView. UIActionSheet 和 UIAlertController
- iOS学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- IOS学习之路二十四(UIImageView 加载gif图片)
- iOS学习之路-图片轮播(UIScrollerView)
- IOS学习之navigationBar上添加图片(UIImageView)以及文字(UILabel)
- iOS学习基础学习之动态添加Button和监听UIAlertView按钮
- iOS学习之动态添加Button和监听UIAlertView按钮
- IOS学习之路十四(用TableView做的新闻客户端展示页面)
- IOS UITapGestureRecognizer 遇到父view添加UIImageView的背景图片,子subview的tap事件不起作用了
- 【学习ios之路:UI系列】实现将图片保存到IOS自带的Photo Album中
- IOS学习 NSOperation cell存储图片思路 沙盒路径查找 数组中添加空对象 block循环引用风险
- ios客户端学习-如何在storyboard中给一个viewController添加navigationController
- IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)
- 【学习ios之路:UI系列】获取通过UIImagePackerController获取的系统相册图片的名称信息及保存系统相册到本地