int dx = (int)CGRectGetMaxX(coverView.frame)+10;
int dy = (int)self.frame.size.width-CGRectGetMaxX(coverView.frame)-5;
titleView = [[UILabel alloc] initWithFrame:CGRectMake(dx, padding,dy , 20)];
titleView.center = [self roundedCenterPoint:titleView.center];
[titleView setBackgroundColor:[UIColor clearColor]];
[titleView setTextColor:[UIColor blackColor]];
[titleView setFont:[UIView yoda_fontWithType:YODA_FONT_TABLEVIEWCELL_TITLE]];
titleView.numberOfLines = 0;
titleView.opaque = YES;
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
然后在创建后添加到UIatbleviewCell
[self addSubview:titleView];
此方法设置文本并通过标签框架上的类别设置
-(void) setTitle:(NSString*)title
{
[titleView setText:title];
[titleView setVerticalAlignmentTop];
}
圆角中心点
-(CGPoint)roundedCenterPoint:(CGPoint) pt {
return CGPointMake(round(pt.x), round(pt.y));
}
UIlabel类别方法
- (void) setVerticalAlignmentTop
{
CGSize textSize = [self.text sizeWithFont:self.font
constrainedToSize:self.frame.size
lineBreakMode:self.lineBreakMode];
CGRect textRect = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width,
ceilf(textSize.height));
[self setFrame:CGRectIntegral(textRect)];
[self setNeedsDisplay];
}
答案 0 :(得分:1)
第一行
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
像这样添加UIViewAutoresizingFlexibleHeight
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
第二次增加标签的高度,就像你现在设置的那样20使其成为30并检查。
答案 1 :(得分:0)
因为titleView
帧正在使用浮动数字。
要强制框架的整数值,只需插入以下代码行:
[titleView setFrame:CGRectIntegral(titleView.frame)];
行后
titleView = [[UILabel alloc] initWithFrame:CGRectMake(dx, padding,dy , 20)];