objective-c - UILabel 在 UISlider 拇指上

标签 objective-c

我如何将 UILabel 放在 UISlider 的拇指上...这样当我移动拇指时...UILabel 也会移动...就像在拇指上一样...

有什么想法吗??

最佳答案

试试这个

yourLabel = [[UILabel alloc]initWithFrame:....];

//Call this method on Slider value change event

-(void)sliderValueChanged{
    CGRect trackRect = [self.slider trackRectForBounds:self.slider.bounds];
    CGRect thumbRect = [self.slider thumbRectForBounds:self.slider.bounds
                               trackRect:trackRect
                                   value:self.slider.value];

    yourLabel.center = CGPointMake(thumbRect.origin.x + self.slider.frame.origin.x,  self.slider.frame.origin.y - 20);
}

通过使用此代码段,我可以获得最准确的值。

关于objective-c - UILabel 在 UISlider 拇指上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3510961/

相关文章:

ios - 更改项目名称后 Xcode 8 核心数据应用程序崩溃

objective-c - 计算连接/下载速度

iphone - 如何在Objective C代码中使用Class对象

iphone - iOS 媒体选择器不显示

ios - UITableViewCell willDisplayCell 方法难题

objective-c - 将 xcode 项目上传到应用商店

ios - 如何在单元格 iOS 中为按钮设置标签?

ios - UICollectionView 旋转动画

objective-c - NSAlert 提示输入由以 root 身份运行的进程生成的文本

ios - 如何水平和垂直滚动 CollectionView 单元格..我正在使用 9 个单元格 CollectionView