首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

控件的应用

2012-06-26 
控件的使用创建UIButton?创建一个动画?// Create sliderUISlider *slider [[UISlider alloc] initWithFr

控件的使用

创建UIButton

?

创建一个动画

?

// Create sliderUISlider *slider = [[UISlider alloc] initWithFrame:baseFrame];slider.center = CGPointMake(160.0f, 140.0f);slider.value = 0.0f;// Create the callbacks for touch, move, and release[slider addTarget:self action:@selector(startDrag:) forControlEvents:UIControlEventTouchDown];[slider addTarget:self action:@selector(updateThumb:) forControlEvents:UIControlEventValueChanged];[slider addTarget:self action:@selector(endDrag:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];// Present the slider[self.view addSubview:slider];[self performSelector:@selector(updateThumb:) withObject:slider afterDelay:0.1f];//创建图片的例子- (UIImage *) createImageWithLevel: (float) aLevel{UIGraphicsBeginImageContext(CGSizeMake(40.0f, 100.0f));CGContextRef context = UIGraphicsGetCurrentContext();float INSET_AMT = 1.5f;// Create a filled rect for the thumb[[UIColor darkGrayColor] setFill];CGContextAddRect(context, CGRectMake(INSET_AMT, 40.0f + INSET_AMT, 40.0f - 2.0f * INSET_AMT, 20.0f - 2.0f * INSET_AMT));CGContextFillPath(context);// Outline the thumb[[UIColor whiteColor] setStroke];CGContextSetLineWidth(context, 2.0f);CGContextAddRect(context, CGRectMake(2.0f * INSET_AMT, 40.0f + 2.0f * INSET_AMT, 40.0f - 4.0f * INSET_AMT, 20.0f - 4.0f * INSET_AMT));CGContextStrokePath(context);// Create a filled ellipse for the indicator[[UIColor colorWithWhite:aLevel alpha:1.0f] setFill];CGContextAddEllipseInRect(context, CGRectMake(0.0f, 0.0f, 40.0f, 40.0f));CGContextFillPath(context);// Label with a numberNSString *numstring = [NSString stringWithFormat:@"%0.1f", aLevel];UIColor *textColor = (aLevel > 0.5f) ? [UIColor blackColor] : [UIColor whiteColor];centerText(context, @"Georgia", 20.0f, numstring, CGPointMake(20.0f, 20.0f), textColor);// Outline the indicator circle[[UIColor grayColor] setStroke];CGContextSetLineWidth(context, 3.0f);CGContextAddEllipseInRect(context, CGRectMake(INSET_AMT, INSET_AMT, 40.0f - 2.0f * INSET_AMT, 40.0f - 2.0f * INSET_AMT));CGContextStrokePath(context);// Build and return the imageUIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return theImage;}//设置UISlider点击和正常两种状态// create a new custom thumb image and use it for the highlighted stateUIImage *customimg = [self createImageWithLevel:aSlider.value];[aSlider setThumbImage: simpleThumbImage forState: UIControlStateNormal];[aSlider setThumbImage: customimg forState: UIControlStateHighlighted];previousValue = aSlider.value;
?

?

?

?

?

?

预留

预留

预留

预留

预留

预留

热点排行