52 lines
1.6 KiB
Swift
52 lines
1.6 KiB
Swift
//
|
||
// AV_ScrollingScaleView.swift
|
||
// anniversary_Project
|
||
//
|
||
// Created by 忆海16 on 2024/7/8.
|
||
//
|
||
|
||
import UIKit
|
||
|
||
class AV_ScrollingScaleView: UIView {
|
||
private let scrollView = UIScrollView()
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
setupScrollView()
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
super.init(coder: coder)
|
||
setupScrollView()
|
||
}
|
||
|
||
private func setupScrollView() {
|
||
scrollView.frame = self.bounds
|
||
scrollView.backgroundColor = .white
|
||
self.addSubview(scrollView)
|
||
|
||
// 设置内容大小
|
||
let contentWidth: CGFloat = 4000 // 2000刻度,每个刻度宽度为2个单位
|
||
scrollView.contentSize = CGSize(width: contentWidth, height: self.bounds.height)
|
||
|
||
// 添加刻度标签
|
||
for i in 0...2000 {
|
||
let xPosition = CGFloat(i) * 2.0
|
||
let label = UILabel(frame: CGRect(x: xPosition, y: self.bounds.midY - 10, width: 50, height: 20))
|
||
label.text = "\(i)ml"
|
||
label.textColor = .black
|
||
label.textAlignment = .center
|
||
|
||
if i % 100 == 0 { // 每100个刻度加一个较大标签
|
||
label.font = UIFont.boldSystemFont(ofSize: 12)
|
||
label.frame = CGRect(x: xPosition, y: self.bounds.midY - 10, width: 50, height: 20)
|
||
} else {
|
||
label.font = UIFont.systemFont(ofSize: 10)
|
||
}
|
||
|
||
scrollView.addSubview(label)
|
||
}
|
||
}
|
||
|
||
}
|