我正在嘗試用UISlider
更改線條筆畫,但它不起作用。滑塊值沒問題,但沒有任何變化。 滑塊在顯示屏上運行,並在標籤上返回一個值。我認爲這個函數在第一次加載時被繪製,而不是停下來。但我不知道如何解決這個問題。用uislider更改CGContextSetLineWidth
我.h
文件:
#import <UIKit/UIKit.h>
@interface Draw : UIView {
IBOutlet UISlider *slider;
IBOutlet UILabel *label;
}
- (IBAction)sliderValueChanged:(id)sender;
@end
我.m
文件:
#import "Draw.h"
@implementation Draw
- (IBAction) sliderValueChanged:(UISlider *)sender {
label.text = [NSString stringWithFormat:@"%.1f", slider.value];
NSLog(@"slider value = %f", sender.value);
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect;
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 50.0, 50.0);
CGContextAddLineToPoint(context, 250.0, 100.0);
CGContextAddLineToPoint(context, 250.0, 350.0);
CGContextAddLineToPoint(context, 50.0, 350.0);
CGContextClosePath(context);
CGContextSetLineWidth(context, slider.value);
CGContextStrokePath(context);
}
@end
ya,正確的提示,謝謝! – greenchapter 2013-04-10 20:09:20