objective-c – UILabel文本对齐权

objective-c – UILabel文本对齐权,第1张

概述我希望我的文字应该正确对齐. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"lisn"];cell 我希望我的文字应该正确对齐.

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{UItableVIEwCell *cell=[tableVIEw dequeueReusableCellWithIDentifIEr:@"lisn"];cell=[[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:@"lisn"] autorelease];CGSize  textSize = { 210.0,10000.0 };CGSize size = [[gMessageArray objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:textSize lineBreakMode:UIlineBreakModeWorDWrap];UILabel *lisnerMessage=[[[UILabel alloc] init] autorelease];lisnerMessage.backgroundcolor = [UIcolor clearcolor];[lisnerMessage setFrame:CGRectMake(75,20,size.wIDth + 5,size.height+2)];lisnerMessage.numberOflines=0;lisnerMessage.textAlignment=UITextAlignmentRight;lisnerMessage.text=[gMessageArray objectAtIndex:indexPath.row];[cell.contentVIEw addSubvIEw:lisnerMessage];return cell}

但我的文字不对齐请帮助

解决方法 因为您使用sizeWithFont然后将框架设置为该大小,所以您的文本是正确对齐的.尝试在标签上添加浅灰色背景颜色,看看我在说什么.您的标签应设置为与表格单元格相同的大小,并允许文本在其中流动.然后它会向右对齐.

更新样本

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"lisn"];    cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:@"lisn"];    UILabel *lisnerMessage = [[UILabel alloc] init];    lisnerMessage.backgroundcolor = [UIcolor clearcolor];    [lisnerMessage setFrame:cell.frame];    lisnerMessage.numberOflines = 0;    lisnerMessage.textAlignment = NSTextAlignmentRight;    lisnerMessage.text = [gMessageArray objectAtIndex:indexPath.row];    [cell.contentVIEw addSubvIEw:lisnerMessage];    return cell}
总结

以上是内存溢出为你收集整理的objective-c – UILabel文本对齐权全部内容,希望文章能够帮你解决objective-c – UILabel文本对齐权所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1059699.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存