鉴于以下图像:定位UIView里面的UIView
三个标签:“今日,平均,最后一周”动态定位在我的ViewController。当应用程序部署到其他设备(如iPhone 6 Plus)时,如果它们没有正确定位,这会成为问题。
我知道能够使用AutoLayout,但我想正确使用用于生成3个活动栏的库来定位它们。
我正在使用的库是:CHCircleGauge。
我尝试将下列内容添加到此库中,但不确定使用哪种约束来将它们放置在此图像中的位置。
这是我使用迄今的代码,其中是所使用来定位标签“6小时”水平和垂直方向为中心的same code。
NSDictionary *valueLabelDictionary = @{@"valueText" : self.valueTextLabel};
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[valueText]|" options:0 metrics:nil views:valueLabelDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[valueText]|" options:0 metrics:nil views:valueLabelDictionary]];
我只是简单地添加了以下内容,至少可以在动态约束条件下使用,并且可以成功地将标签放置在相同的位置。但问题是我不太清楚如何像上图一样完美地定位它们。
NSDictionary *titleLabelDictionary = @{@"titleText" : self.titleTextLabel};
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[titleText]|" options:0 metrics:nil views:titleLabelDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[titleText]|" options:0 metrics:nil views:titleLabelDictionary]];
任何帮助将不胜感激。我仍然试图让我的头像如何AutoLayout和约束的工作。
UPDATE:
为了显示三个环我使用下面的:
var barView1 = CHCircleGaugeView(frame: CGRectMake(0, 0, 245, 245))
barView1.center = CGPointMake(self.gaugeView.frame.size.width/2, self.gaugeView.frame.size.height/2)
barView1.gaugeWidth = 16
barView1.gaugeTintColor = UIColor(red: 255/255, green: 202/255, blue: 76/255, alpha: 1)
barView1.trackWidth = barView1.gaugeWidth
barView1.trackTintColor = UIColor(red: 255/255, green: 202/255, blue: 76/255, alpha: 0.1)
self.gaugeView.addSubview(barView1)
barView1.setValue(0.10, animated: true)
然后,我只是增加两个是更小的尺寸(在gaugeView
居中)的配合内更大的戒指。
更新2:
最后我用了一些constant
填充如下:
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleTextLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:-9.0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self.titleTextLabel
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:-14.0]];
你是否控制每个环的厚度? – 2015-02-12 03:59:23
@AaronBrager:是的,这是通过将对象的'gaugeWidth'和'trackWidth'属性设置为'16'来完成的。 – fuzz 2015-02-12 04:00:52