自己看的东西:UIWebView UIAlertController UIPickerView
2015-10-21 14:53
344 查看
1.UIWebView:
- (void)viewDidLoad { [super viewDidLoad]; self.webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds]; NSURLRequest *reduest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]; [self.webView loadRequest:reduest]; [self.view addSubview:self.webView]; self.webView.delegate = self; // Do any additional setup after loading the view, typically from a nib. } -(void)webViewDidStartLoad:(UIWebView *)webView { NSLog(@"STARTing"); } -(void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"finish......"); #pragma mark----将你设置的背景图和小菊花删除 { [self.act stopAnimating]; UIView *ab = (UIView *)[self.view viewWithTag:103];//用tag强转 因为之前view1不是属性,不能直接用self点出来 [ab removeFromSuperview]; } } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { NSLog(@"error"); #pragma mark--当加载网页出错的时候:设置背景图和小菊花,一直缓冲 数据出来之后,删除背景图与菊花 { UIView *view1 = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; view1.backgroundColor = [UIColor redColor]; [self.view addSubview:view1]; view1.alpha = 0.3; self.act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 100, 50, 50)]; self.act.center = view1.center; self.act.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; [view1 addSubview:self.act]; view1.tag = 103; [self.act startAnimating]; } }
2. UIAlertController:
AppDelegate.m- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; RootViewController *rootVC = [[RootViewController alloc] init]; UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC]; self.window.rootViewController = naVC; return YES; }RootViewController.m:
- (void)viewDidLoad { [super viewDidLoad]; #pragma mark-----1. 初始化 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定" message:@"取消" preferredStyle:UIAlertControllerStyleAlert]; #pragma mark-----2. 添加类似于按钮的东西 block里面写点击后的操作 // 三种按钮的格式default cancel destructive: UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"default" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"11111"); // 获取输入框里的文本内容:需要强转一下(xcode6) UITextField *str = (UITextField *)alert.textFields[0]; NSLog(@"%@", str.text); }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style: UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"22222"); }]; UIAlertAction *destruAction = [UIAlertAction actionWithTitle:@"destructive" style: UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { NSLog(@"333333"); }]; #pragma mark-----3. 添加输入框: [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.text = @"smg"; }]; [alert addAction:defaultAction]; [alert addAction:cancelAction]; [alert addAction:destruAction]; [self presentViewController:alert animated:YES completion:nil]; }
3. UIPickerView:
先学习UITableView 这个就简单了#import "ViewController.h" @interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource> @property (nonatomic,strong) UIPickerView *pick; @property (nonatomic,strong) NSMutableArray *arrayData; @property (nonatomic,strong) NSMutableArray *arrayData2; @property (nonatomic,strong) NSMutableArray *arrayData3; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 初始化同样是三步: self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 50, 350, 200)]; self.pick.backgroundColor = [UIColor redColor]; [self.view addSubview:self.pick]; //和tableView类似 遵循两个协议:<UIPickerViewDelegate,UIPickerViewDataSource> self.pick.delegate = self; self.pick.dataSource = self; self.arrayData = [NSMutableArray arrayWithObjects:@"水瓶座",@"双鱼座",@"白羊座",@"金牛座",@"双子座",@"巨蟹座",@"狮子座",@"处女座",@"天秤座",@"天蝎座",@"射手座",@"山羊座", nil]; self.arrayData2 = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", nil]; self.arrayData3 = [NSMutableArray arrayWithObjects:@"2010" , @"2011", @"2012", @"2013",@"2014",@"2015",@"2016", @"2017", nil]; // 加载视图时显示的是第几列的第几行 行列都是从0开始 //Component:列 row:行 [self.pick selectRow:4 inComponent:1 animated:YES]; } #pragma mark 1. 设置某列中每行的高度 - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { return 30; } #pragma mark 2. 设置列数 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 3; } #pragma mark 3. 设置某列中的行数 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if (component == 0) { return self.arrayData3.count; }else if (component == 1) { return self.arrayData2.count; }else { return self.arrayData.count; } } #pragma mark 4. 每列中每行显示的内容 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component == 0) { return self.arrayData3[row]; }else if (component == 1) { return self.arrayData2[row]; }else { return self.arrayData[row]; } } #pragma mark 5. 选中的响应事件 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { if (component == 0) { NSLog(@"%@", self.arrayData3[row]); }else if (component == 1) { NSLog(@"%@", self.arrayData2[row]); }else { NSLog(@"%@", self.arrayData[row]); } }
补充:
// 可永久保存数据 NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; [user setValue:@"wang" forKey:@"userName"];
4. UIImagePickerController:
- (void)viewDidLoad { [super viewDidLoad]; self.imV = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)]; self.imV.layer.cornerRadius = 150; self.imV.backgroundColor = [UIColor redColor]; self.button = [UIButton buttonWithType:UIButtonTypeCustom]; self.button.frame = CGRectMake(50, CGRectGetMaxY(self.imV.frame)+30, 100, 50); [self.button setTitle:@"ha" forState:UIControlStateNormal]; self.button.backgroundColor = [UIColor blackColor]; // 设置这个属性之后,选中的图片会和你设置的imV边框一致 (而不是方的) self.imV.layer.masksToBounds = YES; // 给按钮添加事件 跳转到系统相册 [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:self.button]; [self.view addSubview:self.imV]; } #pragma mark ==== ==== 按钮的响应事件: - (void)buttonAction:(UIButton *)sender { // 系统封装的控制器 初始化一下就可以 UIImagePickerController *pickerVC = [[UIImagePickerController alloc] init]; // 设置代理 遵守两个协议:<UIImagePickerControllerDelegate,UINavigationControllerDelegate> pickerVC.delegate = self; // 可以编辑图片 pickerVC.allowsEditing = YES; // xcode6这样写 才会显示系统相册 pickerVC.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentViewController:pickerVC animated:YES completion:nil]; } #pragma mark ==== ==== 选中系统相册图片: - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // 选中系统的图片后 将其返回到自己设置的imV上显示 self.imV.image = [info objectForKey:UIImagePickerControllerOriginalImage]; [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark ==== ==== 点击取消的时候: - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { NSLog(@"CANCEL..."); [self dismissViewControllerAnimated:YES completion:nil]; }
5. UIDatePicker:
// 初始化 self.datePicker = [[UIDatePicker alloc] init]; [self.datePicker setDatePickerMode:UIDatePickerModeDate]; [self.datePicker setMaximumDate:[NSDate date]]; [self.view addSubview:self.datePicker];
6. 调用电话 短信:
还有一个mailto- (void)viewDidLoad { [super viewDidLoad]; //调用网址 // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]]; // 调用发送短信 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://10086"]]; // 调用打电话 // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]]; MFMessageComposeViewController *MF = [[MFMessageComposeViewController alloc] init]; if ([MFMessageComposeViewController canSendText]) { MF.body = @"hello word"; MF.recipients = @[@"10086"]; MF.messageComposeDelegate = self; [self presentViewController:MF animated:YES completion:nil]; } } - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { switch (result) { case MessageComposeResultSent: NSLog(@"ok"); break; case MessageComposeResultFailed: NSLog(@"fail"); break; case MessageComposeResultCancelled: NSLog(@"cancel"); break; default: break; } }
7. UIWindowLevel:
UIWindowLevel 只是window的层级关系 有三种情况:UIWindowLevelNormal UIWindowLevelStatusBar UIWindowLevelAlert默认是UIWindowLevelNormal是最底层 中间是UIWindowLevelStatusBar 最上层:UIWindowLevelAlert
8. 谓词:
NSArray *arrayPerson = [NSArray arrayWithObjects: [Person personWithName:@"zhang" age:10] , [Person personWithName:@"3" age:15], [Person personWithName:@"1" age:23], [Person personWithName:@"1z" age:5], [Person personWithName:@"2" age:34], nil]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = '1' && age > 20"]; NSArray *array1 = [arrayPerson filteredArrayUsingPredicate:predicate]; NSLog(@"%@", array1); NSPredicate *precidate2 = [NSPredicate predicateWithFormat:@"name IN {'zhang','2','3'} || age IN {30, 50}"]; NSArray *array2 = [arrayPerson filteredArrayUsingPredicate:precidate2]; NSLog(@"%@", array2);
筛选条件:
@"name contains 'z'"
@"name like '*z'"
like '?'// 问号代表一个字符 *:表示多个字符
BEGINSWITH 'z'// 以什么开始 (大小写敏感)
ENDSWITH 'z' // 以什么结束 (大小写敏感)
相关文章推荐
- 几个iOS工程通用模块介绍
- global.asax、global.asax.compiled、PrecompiledApp.config三者关系
- Android_07_有序广播及最终广播接收者
- iOS 自定义button
- Firemonkey Android IOS 图标
- Android中RelativeLayout各个属性的含义
- 用CocoaPods做iOS程序的依赖管理
- 如何在Android Studio中放置assets文件夹
- Jenkins系列之—22 Android Emulator Plugin插件
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- Object-C 中各数据类型转换 NSData转NSString,Byte,UIImage
- WINDOWS下,中文JSON格式读取报错处理:ValueError: No JSON object could be decoded
- Android 为什么获取到的控件的高度是0
- Android数据存储(4):SQLite Database
- 在android studio中创建selector xml
- android 线程解析
- Android文件命名规范
- Android QQ技术分享三(QQ换肤之SkinEngine实现)
- ios断点续传:NSURLSession和NSURLSessionDataTask实现
- iOS开发系列--地图与定位