ios - Swift - 如何确保标签跟随 slider 的缩略图?

标签 ios iphone swift

我需要使用 swift 开发自定义 UISlider。问题是我不知道如何确保标签跟随 slider 的缩略图,如下所示:

enter image description here

到目前为止我的代码

import Foundation
import UIKit

class Slider: UISlider {

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.layer.borderColor = UIColor.redColor().CGColor
        self.layer.borderWidth = 0.2
        self.tintColor = UIColor.redColor()
    }
}

最佳答案

这个方法可能值得一看,它不能直接调用,但你可以在子类化时使用它

func thumbRectForBounds(_ bounds: CGRect,
              trackRect rect: CGRect,
                  value value: Float) -> CGRect

关于此的更多信息 questionhere

关于ios - Swift - 如何确保标签跟随 slider 的缩略图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31154979/

相关文章:

swift - 无法快速将字典的 int 值转换为 String

ios - 在 Swift 中使用 uiimagePickerController 在同一 View Controller 中选取两个不同的图像

objective-c - 选择 UITableView 中的单元格时更新 UILabel

ios - SpriteKit - 为什么我的游戏在发布新的 iOS 版本时出现错误?

iOS8 + UIDeviceOrientationDidChangeNotification 没有被调用

ios - 应用程序在 iPhone 5 上运行就像在 iPhone 4 上一样

iphone - MKAnnotationView 的不同字体

iphone - 来自字符串数组 iOS 的索引表

ios - SplitViewController DetailView 没有延伸到 TabBarController 后面

ios - 如何将文本转换为 UIImage(使用 GPU)