UISegment分段控件
//分段控件UISegment
NSArray *titles = [[NSArrayalloc]initWithObjects:@"最热",@"最新",@"动态",nil];
UISegmentedControl *segment = [[UISegmentedControlalloc]initWithItems:titles];
segment.segmentedControlStyle =UISegmentedControlStyleBezeled;
//添加背景图片
[segment setImage:[UIImageimageNamed:@"1.png"]forSegmentAtIndex:0];
[segment setImage:[UIImageimageNamed:@"2.png"]forSegmentAtIndex:1];
[segment setImage:[UIImageimageNamed:@"3.png"]forSegmentAtIndex:2];
segment.tintColor = [UIColorgrayColor]; //tinColor一般用于设置前景色
segment.center =CGPointMake(160,40);
[self.viewaddSubview:segment];
// segment.selectedSegmentIndex = 0;//默认选中第几个分段
[segment addTarget:selfaction:@selector(segment:)forControlEvents:UIControlEventValueChanged];//只要是继承UIControll的类都会有这个方法
//UIControll是所有控件的父类
-(void)segment:(UISegmentedControl *)aSegment
{
//通过选中的Index来获取选中的标题
NSString *selectedTitle = [aSegment titleForSegmentAtIndex:aSegment.selectedSegmentIndex];
NSLog(@"%@",selectedTitle);
}
UISlider滑块控件
//滑块控件UISlider›
UISlider *slider = [[UISlideralloc]initWithFrame:CGRectMake(0,0, 200, 30)];
slider.center = CGPointMake(160, 88);
slider.minimumValue = 0;
slider.minimumTrackTintColor = [UIColorredColor];
slider.maximumValue = 1;
slider.maximumTrackTintColor = [UIColorgreenColor];
slider.maximumValueImage = [UIImageimageNamed:@"1.png"];
slider.minimumValueImage = [UIImageimageNamed:@"2.png"];
[slider addTarget:selfaction:@selector(sliderValueChange:)forControlEvents:UIControlEventValueChanged];
[self.viewaddSubview:slider];
[slider release];
-(void)sliderValueChange:(UISlider *)aSlider
{
if (imgView.isAnimating)
{
[imgViewstopAnimating];
}
imgView.animationDuration = aSlider.value;
[imgViewstartAnimating];
}
UIImageView
//UIImageView
imgView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 150,200)];
imgView.userInteractionEnabled =YES;
imgView.center = CGPointMake(160,200);
imgView.image = [UIImageimageNamed:@"run1.tiff"];
[self.viewaddSubview: imgView];
NSArray *imgs = [NSArrayarrayWithObjects:
[UIImage imageNamed:@"run1.tiff"],
[UIImage imageNamed:@"run2.tiff"],
[UIImage imageNamed:@"run3.tiff"],
[UIImage imageNamed:@"run4.tiff"],
[UIImage imageNamed:@"run5.tiff"],
[UIImage imageNamed:@"run6.tiff"],
nil];
//设置动画数组
imgView.animationImages = imgs;
//设置动画时间
imgView.animationDuration =1;
[imgViewstartAnimating];
//ios不支持jif格式的图片,要做动图效果,就要将有一帧,第二种解决方案使用第三方的类库
/*UIEvent事件类,包括点击,晃动,远程监控事件
事件的响应链
接收事件--->application---->window----->ViewController----->View
丢弃事件<--- <---- <---- <----
怎样获取view所在的viewcontroller 通过响应链
*/
各种手势
//轻拍手势
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap:)];
tapGR.numberOfTapsRequired =1;
[imgViewaddGestureRecognizer:tapGR];
[tapGRrelease];
//长按手势
[imgViewremoveGestureRecognizer:tapGR];//在长按之前先将轻拍手势移除
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longPress:)];
[imgViewaddGestureRecognizer:longPress];
[longPressrelease];
//轻扫手势
[imgViewremoveGestureRecognizer:longPress];
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(swipe:)];
swipe.direction =UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionRight ;
[imgViewaddGestureRecognizer:swipe];
[swiperelease];
//旋转手势
[imgViewremoveGestureRecognizer:swipe];
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotation:)];
[imgViewaddGestureRecognizer:rotation];
[rotationrelease];
//捏合手势
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinch:)];
[imgViewaddGestureRecognizer:pinch];
[pinchrelease];
//拖拽
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(pan:)];
[imgViewaddGestureRecognizer:pan];
[panrelease];
//长按
-(void)longPress:(UILongPressGestureRecognizer *)aLongPressGestureRecognizer
{
//随机产生图片
int rand = arc4random() %7 + 1;
// for (int i = 0 ; i < 20 ; i++ )
// {
// int rand = arc4random() % 7 + 1;
// NSLog(@"%d",rand);
// }
NSString *imgName = [NSStringstringWithFormat:@"h%d.jpeg",rand];
UIImage *img = [UIImageimageNamed:imgName];
imgView.image = img;
}
//轻扫
-(void)swipe:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer
{
int rand = arc4random() %7 + 1;
NSString *imgName = [NSStringstringWithFormat:@"h%d.jpeg",rand];
UIImage *img = [UIImageimageNamed:imgName];
imgView.image = img;
}
//旋转
-(void)rotation:(UIRotationGestureRecognizer *)aRotationGestureRecognizer
{
//旋转的角度 弧度制
imgView.transform =CGAffineTransformRotate(imgView.transform,aRotationGestureRecognizer.rotation);
}
//捏合
-(void)pinch:(UIPinchGestureRecognizer *)aPinchGestureRecognizer
{
imgView.transform =CGAffineTransformScale(imgView.transform,aPinchGestureRecognizer.scale, aPinchGestureRecognizer.scale);
}