简体   繁体   中英

UISlider doesn't show in view

I'm trying to create a UISlider in code, it's fairly simple what I'm doing:

self.slider = [[UISlider alloc] initWithFrame:CGRectMake(66.0, 15.0, 235.0, 23.0)];
self.slider.minimumValue = 0.0;
self.slider.maximumValue = 100.0;
self.slider.continuous = YES;

self.slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:self.slider];

That code goes in my viewDidLoad method and that's pretty much all I need, but the slider will not appear when my view is shown. Tried calling setNeedsDisplay on the view as well and it didn't work.

如果要在代码中创建滑块,则不应为其添加IBOutlet,并且声明应为强(可能已被释放,因为您只有弱引用)。

@property (strong, nonatomic)  UISlider *slider;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM