self.view.backgroundColor = [UIColor whiteColor]; //UISegmentedControl 是iOS中的分段控件,其实是多个button的组合视图,通过切换不同的segment(严格来说,点击不同的button),响应不同的操作. NSArray *titles = @[@"轻拍", @"长按",@"轻扫",@"平移"]; UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:titles]; // //设置默认选中的分段 segmentControl.selectedSegmentIndex = 0; segmentControl.frame = CGRectMake(10, 40, 300, 30); // //给segmentedControl添加响应事件 [segmentControl addTarget:self action:@selector(handleSegmentControl:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:segmentControl]; [segmentControl release]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; view.backgroundColor = [UIColor blackColor]; view.tag = 200; [self.view addSubview:view]; [view release];
//UISlider 滑块控件,比如控制音量,以及控制视频播放进度的滑杆. //滑竿上有一系列的值,代表了一个值的范围,滑动滑竿,根据滑竿的值做出相应的改变. UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(30, 60, 200, 30)]; //设置滑竿的最大值 slider.maximumValue = 1.0; //设置滑竿的最小值 slider.minimumValue = 0.0; //给slider添加响应事件 [slider addTarget:self action:@selector(handleSlider:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:slider]; [slider release]; //代码截屏 //(1)设置要截屏的图片大小 UIGraphicsBeginImageContext(self.view.frame.size); //(2)对哪个视图截图固定大小的图片 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; // //(3)获取截图的图片对象 UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); // //(4)结束绘制图片 UIGraphicsEndImageContext(); // //(5)保存到相册 UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
原文地址:http://blog.csdn.net/lunlun426/article/details/39716687