如何对齐标签的文本?

发布于 2024-11-26 08:55:07 字数 174 浏览 2 评论 0原文

我想将标签的文本右对齐。但问题是我的标签位于 UITableViewCell 中,并且我正在使用 UITableViewCell 的“Value1”。所以我想将detailText标签与单元格的右侧对齐,但有时标签位于两行或三行中,因此在这种情况下,我希望标签的下一行左对齐,以便看起来下一行是从左边。

请帮忙!!!!

I want to align the text of my label to right aligned. But the problem is my label is in UITableVIewCell and i am using 'Value1' of UITableViewCell. So i want to align detailText label to the right side of the cell but sometimes the labels is in two or three lines so in that case i want the next line of the label to be left aligned so that it looks the next line is starting from left.

Please help!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2024-12-03 08:55:07

您可以使用自定义表格视图单元格。将 UITableViewCell 类添加到您的项目中并将其命名为 CustomCell,在 Iterface Builder 中创建一个 TableViewCell。添加两个标签,一个右对齐称为“label1”,另一个左对齐称为“label2”,或者做你想做的事情,然后你可以在你的主类中使用它,如下所示:

#import "CustomCell.h"

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

cell.label1.text = @"some rightAlignedText";
cell.label2.text = @"some leftAlignedText";

return cell;

}

You can use custom tableview cells. Add a UITableViewCell class to your project and call it CustomCell, create a TableViewCell in Iterface Builder. Add two Labels, One right aligned called "label1", the other one left aligned called "label2", or do what ever you want, Then you can use it in your main class like this:

#import "CustomCell.h"

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

cell.label1.text = @"some rightAlignedText";
cell.label2.text = @"some leftAlignedText";

return cell;

}

我家小可爱 2024-12-03 08:55:07

您需要查看不同的单元格类型或创建自己的自定义单元格类型,因为据我所知,每个表格单元格的布局方式都是一成不变的

You need to look at a different cell type or create your own custom one because as far as I know, the way each table cell is laid out is set in stone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文