-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPickerLabels.swift
39 lines (29 loc) · 1.17 KB
/
PickerLabels.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// PickerLabels.swift
// My Timer
//
// Created by Luís Machado on 02/02/17.
// Copyright © 2017 LuisMachado. All rights reserved.
//
import Foundation
import UIKit
extension UIPickerView {
func setPickerLabels(labels: [Int:UILabel], containedView: UIView) { // [component number:label]
let fontSize:CGFloat = 20
let labelWidth:CGFloat = containedView.bounds.width / CGFloat(self.numberOfComponents)
let x:CGFloat = self.frame.origin.x
let y:CGFloat = (self.frame.size.height / 2) - (fontSize / 2)
for i in 0...self.numberOfComponents {
if let label = labels[i] {
if self.subviews.contains(label) {
label.removeFromSuperview()
}
label.frame = CGRect(x: x + labelWidth * CGFloat(i), y: y, width: labelWidth, height: fontSize)
label.font = UIFont.boldSystemFont(ofSize: fontSize)
label.backgroundColor = .clear
label.textAlignment = NSTextAlignment.center
self.addSubview(label)
}
}
}
}