UISlider
으로 줄 획을 변경하려고하지만 작동하지 않습니다. 슬라이더 값은 괜찮지 만 아무것도 변경되지 않습니다. 슬라이더가 디스플레이에 나타나고 실행되어 레이블에 값을 되돌립니다. 나는 함수가 첫 번째 하중에서 끌어 당겨지고 멈추는 것보다 더 중요하다고 생각한다. 하지만 그 문제를 어떻게 해결해야할지 모르겠다. uislider를 사용하여 CGContextSetLineWidth 변경
.h
파일 :
#import <UIKit/UIKit.h>
@interface Draw : UIView {
IBOutlet UISlider *slider;
IBOutlet UILabel *label;
}
- (IBAction)sliderValueChanged:(id)sender;
@end
내 .m
파일 : 내용이 다시 그려야 할 필요가 뷰를 알려 [self setNeedsDisplay]
를 호출해야 - (IBAction) sliderValueChanged:(UISlider *)sender
당신의 방법에서
#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
예, 감사합니다. – greenchapter