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;
then after creating it is added to UIatbleviewCell
[self addSubview:titleView];
this method sets the text and through a category on label frame is set
-(void) setTitle:(NSString*)title
{
[titleView setText:title];
[titleView setVerticalAlignmentTop];
}
for rounding centre points
-(CGPoint)roundedCenterPoint:(CGPoint) pt {
return CGPointMake(round(pt.x), round(pt.y));
}
UIlabel Category method
- (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];
}
First in this line
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
add UIViewAutoresizingFlexibleHeight
like this
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Second increase height of label like currently you are setting 20 make it 30 and check.
Its because the titleView
frame is using floating numbers.
To force integers value for your frame just insert the following line of code:
[titleView setFrame:CGRectIntegral(titleView.frame)];
after the line
titleView = [[UILabel alloc] initWithFrame:CGRectMake(dx, padding,dy , 20)];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.