gpt4 book ai didi

ios - 使用 uislider 更改 CGContextSetLineWidth

转载 作者:行者123 更新时间:2023-11-29 04:00:28 26 4
gpt4 key购买 nike

我正在尝试使用 UISlider 更改线条笔画,但它不起作用。 slider 值没问题,但没有任何改变。 slider 位于显示屏上并运行,并在标签上返回一个值。我认为该函数是在第一次加载时绘制的,然后就停止了。但我不知道如何解决这个问题。

我的.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

最佳答案

在您的方法 - (IBAction) sliderValueChanged:(UISlider *)sender 中,您应该调用 [self setNeedsDisplay] 来通知 View 需要重绘内容。

关于ios - 使用 uislider 更改 CGContextSetLineWidth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15923677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com