作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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/
我正在尝试使用 UISlider 更改线条笔画,但它不起作用。 slider 值没问题,但没有任何改变。 slider 位于显示屏上并运行,并在标签上返回一个值。我认为该函数是在第一次加载时绘制的,然
我想在 UIView 的 drawRect 方法中绘制一条细线宽度的线。我看到的 CGContextSetLineWidth 值为 0.5 的行与用于绘制边框 CALayer 的相同 1.0 宽度值不
使用CGContextSetLineWidth(context, 1),宽度几乎总是至少2个像素,而不是1 QQCandleStickLayer.m -(id)init { self = [s
我是一名优秀的程序员,十分优秀!