cuốn sách gpt4 ai đã làm

ios - 如何使用 slider 更改 UILabel

In lại Tác giả: Walker 123 更新时间:2023-11-28 21:06:31 25 4
mua khóa gpt4 Nike

我是 objective-c 的新手,我想将标签文本更改为 slider 的值。

我应该先添加一些文本,还是应该在 Action 中添加 UILabel?

我有的是:

#import "slRootViewController.h"
@implementation slRootViewController {
NSMutableArray *_objects;
}

- (void)loadView {
[super loadView];

_objects = [[NSMutableArray alloc] init];

self.title = @"Slider Test ";


CGRect frame = CGRectMake(0.0, 0.0, 200.0, 10.0);
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 0.0;
slider.maximumValue = 50.0;
slider.continuous = YES;
slider.value = 25.0;

UILabel *sliderText=[ [UILabel alloc] initWithFrame:CGRectMake(273,442,32,20)];

[self.view addSubview:slider];
[self.view addSubview:sliderText];
}

// voids
-(void)sliderAction:(id)sender
{
UISlider *slider = (UISlider*)sender;
self.sliderText.text=[NSString stringWithFormat:@"%f", slider.value];
//-- Do further actions
}

@kết thúc

但是我收到一个错误提示

error: Use of undeclared identifier "sliderText"

câu trả lời hay nhất

在您的文件中全局定义 Label 对象。

@implementation slRootViewController {
NSMutableArray *_objects;
UILabel *sliderText; //Define globally label object
}

并使用全局对象更改此标签的名称或任何事件,例如更改名称,

sliderText.text = @"Set Name";

设置文字颜色,

sliderText.textColor = [UIColor redColor];

vân vân……

关于ios - 如何使用 slider 更改 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45472195/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress