我正在尝试实现一个约束UITableViewCell子类,一切都运行得很好,除了UILabel.我设置的约束肯定是强制执行的,但是当约束发生冲突时,标签内部的文本不会调整为较小的字体大小.相反,UILabel的高度被截断,字体保持相同的大小,这意味着字母在顶部和底部被切断.
是否有一些方法我必须调用才能使其工作?我认为自动布局足够聪明,可以自动调整字体大小,所以我有点迷失为什么会发生这种情况.
相关守则:
self.label = [[UILabel alloc] initWithFrame:CGRectZero];
self.label.textColor = [UIColor whiteColor];
self.label.translatesAutoresizingMaskIntoConstraints = NO;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.numberOfLines = 1;
[self.contentView addSubview:self.label];
NSLayoutConstraint *otherViewToLabelHorizontalConstraint = // Make sure that the label is always to the right of the other view.
[NSLayoutConstraint constraintWithItem:self.label
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.otherView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0.0];
NSLayoutConstraint *aTextFieldToLabelVerticalConstraint =
[NSLayoutConstraint constraintWithItem:self.label
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.aTextField
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0];
Run Code Online (Sandbox Code Playgroud)
基本上,这些约束是为了执行小区,其中otherView在左边,aTextField是在权otherView在相同的Y电平,并且所述标记是下面aTextField和底部的右侧otherView.
像往常一样,感谢您对此的任何帮助.
在CALayer子类内部绘制函数内部绘制弧时,我遇到了问题.该绘图功能的实现如下:
-(void)drawInContext:(CGContextRef)ctx
{
CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
CGFloat radius = MIN(center.x, center.y);
CGContextBeginPath(ctx);
CGContextAddArc(ctx, center.x, center.y, radius, DEG2RAD(0), DEG2RAD(90), YES);
CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(ctx, 5);
CGContextDrawPath(ctx, kCGPathStroke);
}
Run Code Online (Sandbox Code Playgroud)
这里没有什么太开创性的,但奇怪的是它是逆时针绘制弧形,即使我指定它是顺时针方向.相反,当我为顺时针参数指定NO时,它顺时针绘制圆弧.我对翻转坐标系进行了一些研究,并认为可能是这里的问题,但我不想只是硬编码我所说的相反的bool参数.对于如何解决这个问题,有任何的建议吗?
谢谢!