自己看的东西:UIWebView UIAlertController UIPickerView
发布日期:2022-02-08 18:03:24
浏览次数:76
分类:技术文章
本文共 10346 字,大约阅读时间需要 34 分钟。
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 ()@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类似 遵循两个协议: 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]; // 设置代理 遵守两个协议: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' // 以什么结束 (大小写敏感)
转载地址:https://blog.csdn.net/Evelynzn/article/details/49304517 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月05日 12时29分38秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
python的取余操作
2019-04-26
八皇后问题的解题思路
2019-04-26
动态规划问题
2019-04-26
python中全局变量与局部变量
2019-04-26
内存中堆和栈的区别,以及C语言中的内存模型
2019-04-26
两个单链表的求和,将矩阵元素全部对换
2019-04-26
KMP字符串匹配算法
2019-04-26
图算法:一种比线性表和树更复杂的数据结构
2019-04-26
网络安全工程师的初学路径
2019-04-26
离群点检测和新奇检测之离群点检测
2019-04-26
离群点检测和新奇检测之新奇检测
2019-04-26
几种常见的离群点检验方法
2019-04-26
学习前后端技术的建议
2019-04-26
javascript的介绍,变量let和var声明,变量作用域,解构赋值
2019-04-26
统一资源定位符URL
2019-04-26
HTTP keep-alive详解
2019-04-26
字符编码(python编码机制的过去和现在)
2019-04-26
python序列的高阶函数:map,reduce,filter,sorted
2019-04-26
python模块的定义,和模块的作用域
2019-04-26
面向对象,即class类,类的封装,属性的类别划分,
2019-04-26