我想随着值的变化增加和减少uislider中的圆圈大小..
这是我的代码
绘图.m
- (id)initWithFrame:(CGRect)frame value:(float )x
{
value=x;
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(6,17,value,value);
CGContextAddEllipseInRect(context, rectangle);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillPath(context);
}
和 ViewController.m
@implementation ViewController
@synthesize mySlider,colorLabel;
- (void)viewDidLoad
{ [super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)sliderValue:(UISlider*)sender
{
float r=[[NSString stringWithFormat:@"%.0f",mySlider.value] floatValue];
NSLog(@"value...%f",r);
CGRect positionFrame = CGRectMake(10,100,200,100);
circle = [[draw alloc] initWithFrame:positionFrame value:r];
circle.backgroundColor=[UIColor clearColor];
[self.view addSubview:circle];
}
在这段代码中,圆的大小增加了但没有减少,另一个问题是圆形外观,输出是 .