gpt4 book ai didi

ios - UILabel NSTextAlignmentRight 不起作用?

转载 作者:行者123 更新时间:2023-11-29 01:31:48 25 4
gpt4 key购买 nike

我遇到文本右对齐问题。实际上在我的 DetailedViewController 中有一个名为 "lblnNewsTitle"UILabel,对于这个 Lable,我正在尝试设置 NSTextAlignmentRight 但它对我不起作用。任何人都可以帮我解决这个问题吗?

屏幕截图 1:

enter image description here

屏幕截图 2:

enter image description here

我的 Storyboard截图 3:

enter image description here

这是我的代码:

   - (void)viewDidLoad

{

[DetailTittle setFont:[UIFont fontWithName:@"GEEast-ExtraBold" size:12]];
[super viewDidLoad];

[self.lblDescription setNumberOfLines:0];

[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320, 765)];
self.txtViwNews.text=self.strDescription;
self.lblnNewsTitle.text=self.strTitle;
self.lblnNewsTitle.font=[UIFont fontWithName:@"GEEast-ExtraBold" size:14];
self.txtViwNews.font=[UIFont fontWithName:@"GE SS Unique" size:12];

self.lblnNewsTitle.textAlignment = NSTextAlignmentRight;

self.txtViwNews.textAlignment= NSTextAlignmentRight;

self.lblDateinDetail.text=self.strDate;
self.lblDateinDetail.font=[UIFont fontWithName:@"GEEast-ExtraBold" size:14];
self.lblDateinDetail.textColor=[UIColor blackColor];

[lblnNewsTitle setNumberOfLines:0];
[lblnNewsTitle sizeToFit];


NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.strDetailImage]];
self.strImage.image = [UIImage imageWithData:data];
// Set border color and width of image
[_strImage.layer setBorderColor:[UIColor blackColor].CGColor];
[_strImage.layer setBorderWidth:1.0];
self.lblDescription.font=[UIFont fontWithName:@"GE SS Unique" size:kLblIntalFont];
self.lblDescription.textAlignment = NSTextAlignmentRight;
[self estimatedHeight:kLblIntalFont];

if (_strImage.image == nil)
{
[_strImage.layer setBorderColor:[UIColor blackColor].CGColor];
[_strImage.layer setBorderWidth:0];

[self.lblnNewsTitle setNumberOfLines:0];
self.lblnNewsTitle.frame = CGRectMake(self.lblnNewsTitle.frame.origin.x, self.lblnNewsTitle.frame.origin.y, self.lblnNewsTitle.frame.size.width, self.lblnNewsTitle.frame.size.height );

self.viwMidImage.frame=CGRectMake(self.viwMidImage.frame.origin.x, self.strImage.frame.origin.y, self.viwMidImage.frame.size.width, self.viwMidImage.frame.size.height);
[self.lblDescription setNumberOfLines:0];
[self.lblDescription sizeToFit];
self.lblDescription.frame = CGRectMake(self.lblDescription.frame.origin.x, self.viwMidImage.frame.origin.y+ self.viwMidImage.frame.size.height,self.lblDescription.frame.size.width,self.lblDescription.frame.size.height );
self.lblDescription.textAlignment = NSTextAlignmentRight;
}
else {

// if (!cell.imgNews ==nil)
self.lblnNewsTitle.frame = CGRectMake(self.lblnNewsTitle.frame.origin.x, self.lblnNewsTitle.frame.origin.y, self.lblnNewsTitle.frame.size.width, self.lblnNewsTitle.frame.size.height );
[self.lblDescription setNumberOfLines:0];
[self.lblDescription sizeToFit];

}

}

最佳答案

直接在 Attribute Inspector 中添加 NSTextAlignmentRight,同时删除 [lblnNewsTitle sizeToFit]; 并检查

试试这个

enter image description here

关于ios - UILabel NSTextAlignmentRight 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33370646/

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