ios – 如何正确对齐UILabel在细胞桌面上?

ios – 如何正确对齐UILabel在细胞桌面上?,第1张

概述我创建了一个在self中有tableview类的项目. tableview的任何单元格中都有3个东西. (1个按钮(左侧)和2个标签,如底部图像) 我希望标题单元格正确对齐,但我不能这样做. 这是我的代码.我的错误在哪里: - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentif 我创建了一个在self中有tablevIEw类的项目.
tablevIEw的任何单元格中都有3个东西. (1个按钮(左侧)和2个标签,如底部图像)

我希望标题单元格正确对齐,但我不能这样做.

这是我的代码.我的错误在哪里:

- (ID)initWithStyle:(UItableVIEwCellStyle)style reuseIDentifIEr:(Nsstring *)reuseIDentifIEr{    self = [super initWithStyle:style reuseIDentifIEr:reuseIDentifIEr];    if (self)    {        _backgroundImageVIEw = [[UIImageVIEw alloc] initWithImage:[UIImage imagenamed:@"copymove-cell-bg"]];        [_backgroundImageVIEw setContentMode:UIVIEwContentModetopRight];        [self setBackgroundVIEw:_backgroundImageVIEw];        [self setSelectionStyle:UItableVIEwCellSelectionStyleNone];        _iconbutton = [UIbutton buttonWithType:UIbuttonTypeCustom];        [_iconbutton setFrame:CGRectMake(0,10,47,50)];        [_iconbutton setAdjustsImageWhenHighlighted:NO];        [_iconbutton addTarget:self action:@selector(iconbuttonAction:) forControlEvents:UIControlEventtouchUpInsIDe];        [_iconbutton setimage:[UIImage imagenamed:@"item-icon-folder"] forState:UIControlStatenormal];        [_iconbutton setimage:[UIImage imagenamed:@"item-icon-folder-selected"] forState:UIControlStateSelected];        [_iconbutton setimage:[UIImage imagenamed:@"item-icon-folder-selected"] forState:UIControlStateHighlighted];        [self.contentVIEw addSubvIEw:_iconbutton];        _TitleTextFIEld = [[UILabel alloc] initWithFrame:CGRectMake(69,29,_TitleTextFIEld.frame.size.wIDth,_TitleTextFIEld.frame.size.height)];        [_TitleTextFIEld setFont:KOFont_fileS_Title];        [_TitleTextFIEld setTextcolor:KOcolor_fileS_Title];        [_TitleTextFIEld.layer setShadowcolor:KOcolor_fileS_Title_SHADOW.CGcolor];        [_TitleTextFIEld setautoresizingMask:UIVIEwautoresizingFlexibleleftmargin|UIVIEwautoresizingFlexibleRightmargin];        [_TitleTextFIEld.layer setShadowOffset:CGSizeMake(0,1)];        [_TitleTextFIEld.layer setShadowOpacity:1.0f];        [_TitleTextFIEld.layer setShadowRadius:0.0f];        [_TitleTextFIEld setTextAlignment:UITextAlignmentRight];        [_TitleTextFIEld setlineBreakMode:UIlineBreakModeMIDdleTruncation];        [self.contentVIEw addSubvIEw:_TitleTextFIEld];        [self.layer setMasksToBounds:YES];        _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(273,28)];        [_countLabel setautoresizingMask:UIVIEwautoresizingFlexibleleftmargin|UIVIEwautoresizingFlexibleRightmargin];        [_countLabel setBackgroundcolor:[UIcolor colorWithPatternImage:[UIImage imagenamed:@"item-counter"]]];        [_countLabel setTextAlignment:UITextAlignmentCenter];        [_countLabel setlineBreakMode:UIlineBreakModeMIDdleTruncation];        [_countLabel setFont:KOFont_fileS_COUNTER];        [_countLabel setTextcolor:KOcolor_fileS_COUNTER];        [_countLabel setShadowcolor:KOcolor_fileS_COUNTER_SHADOW];        [_countLabel setShadowOffset:CGSizeMake(0,1)];        [self setAccessoryVIEw:_countLabel];        [self.accessoryVIEw setautoresizingMask:UIVIEwautoresizingFlexibleleftmargin|UIVIEwautoresizingFlexibleBottommargin];    }    return self;}
解决方法 如果您使用的是iOS6,

使用[_countLabel setTextAlignment:NSTextAlignmentCenter];因为在iOS6中不推荐使用UITextAlignmentCenter.

要对齐,

[_countLabel setTextAlignment:NSTextAlignmentRight];

希望这可以帮助你……

总结

以上是内存溢出为你收集整理的ios – 如何正确对齐UILabel在细胞桌面上?全部内容,希望文章能够帮你解决ios – 如何正确对齐UILabel在细胞桌面上?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1020827.html

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

发表评论

登录后才能评论

评论列表(0条)

保存