1. UIButton
1 | CGRect frame = CGRectMake(0, 100, 80, 40); |
2. UIAlertView
1 | UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@"你的内存已满" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil]; |
3. UILabel
1 | UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 10, 200, 34)]; |
4. UITextField
1 |
|
5.UISlider
1 | UISlider *slider =[[UISlider alloc]initWithFrame:CGRectMake(0, 100, 200, 33)]; |
6.UISegmentedControl
1 | UISegmentedControl *seg= [[UISegmentedControl alloc]initWithItems:@[@"骑士",@"勇士"]]; |
7.UIViewImage
1 | UIImageView *imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"head.png" ]]; |
8.UISwitch
1 | UISwitch *uiSwitch=[[UISwitch alloc]initWithFrame:CGRectMake(20, 200, 100, 33)]; |
9.UIActionSheet
1 | UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"微信" otherButtonTitles:@"新浪微博",@"腾讯微博", nil]; |
10.UIWindow
1 | UIWindow *window =[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; |
11.UIBarButtonItem
1 | //左边 |
12.UIWebView
UIWebView 的本地加载HTML页面1
2
3
4
5
6
7
8CGRect rect = [UIScreen mainScreen].bounds;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, rect .size.width,rect.size.height)];
[self.view addSubview:self.webView];
[webView setUserInteractionEnabled:YES];//是否支持交互
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
13.UIPickerView
选择器创建与代理设置
1 | NSArray *pickerArray =@[@"勇士",@"火箭",@"湖人",@"雷霆"]; |
14.UIScrollView
1 | UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, 200, 100)]; |
15.UIProgressView
进度条1
2
3
4
5
6
7
8
9
10
11
12
13UIProgressView *progressView =[[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[self.view addSubview:progressView];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(onTimer:) userInfo:progressView repeats:YES];
-(void) onTimer:(NSTimer *) timer
{
UIProgressView *progress =(UIProgressView *) timer.userInfo;
progress.progress += 0.1;
if(progress.progress == 1.0)
{
progress.progress =0;
}
}
16.UIActivityIndicatorView
活动指示器1
2
3
4
5
6UIActivityIndicatorView *activityView= [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.view addSubview:activityView];
[activityView startAnimating];//播放动画
[activityView stopAnimating];//停止动画
[activityView isAnimating];//判断是否在播放动画
self.view.backgroundColor=[UIColor orangeColor];//背景设置颜色方便预览该组件
17.UINavigationBar
UINavigationBar 导航栏 需要抱一个导航栏目UINavigationItem
1 | UINavigationBar *navbar =[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)]; |
18.UITabBar
1 | UITabBar *tabBar =[[UITabBar alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-44, self.view.frame.size.width, 44)]; |
19.UIApplication
1 | NSURL *appStoreUrl = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"]; |
1 | //退出编辑 |
20.UIRefreshControl
刷新组件,继承了UITableController 有refreshControl 属性存在1
2
3
4
5
6
7
8
9
10UIRefreshControl *refreshControl = [[UIRefreshControl alloc]init];
refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"刷新中.."];
[refreshControl addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
-(void) refreshTableView
{
//刷新后请求
}
21.UIImagePickerController
查看相册1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate = self;
[self presentViewController:pickerController animated:YES completion:nil];
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = image;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
22.UICollectionView
1 | UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init]; |
23.MPMoviePlayerController
视频控制1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *player =[[MPMoviePlayerController alloc]initWithContentURL:url];
player.fullscreen = YES;
CGRect winRect = [[UIScreen mainScreen] applicationFrame];
CGRect rect = CGRectMake(0,0,winRect.size.height, winRect.size.width);
player.controlStyle = MPMovieControlStyleDefault;
player.view.frame = rect;
player.view.center = CGPointMake(rect.size.width/2, rect.size.height/2);
[player.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];
layer.scalingMode = MPMovieScalingModeAspectFill;
[player play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playCompleteFun:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.view addSubview:player.view];
-(void) playCompleteFun:(NSNotification *) notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
常用的一些代码片段记录
视频截图
1 | - (UIImage *) captureFromView: (UIView *) aView |
遇到block的情况下转为self
1 | __weak typeof(self)weakSelf = self; |
常用的一些Build setting 记录
Bitcode 的开启和关闭
pch文件开启和配置路径位置
需要则在Precompile Prefix Header 开启 默认关闭
Prefix Header 则配置相应的路径
例如:$(SRCROOT)/PrefixHeader.pch