gpt4 book ai didi

ios - UILabel 以编程方式添加,在 iphone 6 上显示模糊文本

转载 作者:行者123 更新时间:2023-11-29 12:08:47 25 4
gpt4 key购买 nike

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];
}

最佳答案

这一行的第一个

titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

像这样添加UIViewAutoresizingFlexibleHeight

titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

第二次增加标签的高度,例如当前设置的 20 使其变为 30 并检查。

关于ios - UILabel 以编程方式添加,在 iphone 6 上显示模糊文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34154450/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com