我使用自定义UIView创建此控件,其中4个热点点之间具有相同的空间。我试图在点之下创建标签,看起来第一个标签正确对齐,但我似乎无法弄清楚为什么它们都不正确?
在这里,您可以看到每个点与点上半径之间的空间。
customSlider?.spaceBetweenPoints = 95
customSlider?.radiusPoint = 5
目前的插图:
customSlider?.frame = CGRectMake((self.frame.width-335)/2, 20, 335, 34)
for var i = 0;i<4;i++
{
var xPointSpace = 95
var xPos = xPointSpace * i
var xSpace = (self.frame.width-335)/2
var xWidth = Int(xSpace) + xPos
var xFloat = CGFloat(xWidth)
var textLabel:UILabel = UILabel(frame: CGRectMake(xFloat, 34, 30, 21))
textLabel.text = "lol"
textLabel.backgroundColor = UIColor.redColor()
textLabel.textAlignment = NSTextAlignment.Center
textLabel.font = UIFont(name: "HelveticaNeue", size: 12)
self.addSubview(textLabel)
}
添加标签:
答案 0 :(得分:1)
customSlider?.frame = CGRectMake((self.frame.width-335)/ 2,20,335,34)
for var i = 0;i<4;i++
{
var xPointSpace = 95
var radiusPoint = 5
var xPos = (xPointSpace + radiusPoint * 2)* i
var xSpace = customSlider?.frame.origin.x
var xWidth = xSpace + xPos
var xFloat = CGFloat(xWidth)
var textLabel:UILabel = UILabel(frame: CGRectMake(xFloat, 34, 30, 21))
textLabel.text = "lol"
textLabel.backgroundColor = UIColor.redColor()
textLabel.textAlignment = NSTextAlignment.Center
textLabel.font = UIFont(name: "HelveticaNeue", size: 12)
self.addSubview(textLabel)
}