Center Align text in UITableViewCell problem(UITableViewCell中的文本居中对齐问题)
问题描述
我对 Objective-C 和 iPhone 开发有点陌生,在尝试将文本置于表格单元格中时遇到了问题.我搜索了谷歌,但解决方案是针对已修复的旧 SDK 错误,这些对我不起作用.
I'm kinda new to Objective-C and iPhone development and I've come across a problem when trying to center the text in a table cell. I've searched google but the solutions are for an old SDK bug that has been fixed and these don't work for me.
一些代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Please center me";
cell.textLabel.textAlignment = UITextAlignmentCenter;
return cell;
}
上面的文字没有居中.
我也试过 willDisplayCell 方法:
I have also tried the willDisplayCell method:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
我已经尝试了一些旧发布的解决方案:
and I've tried some of the old posted solutions:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
这些都不会对文本对齐产生任何影响.我的想法已经用完了,任何帮助将不胜感激.
None of these have any effect on the text alignment. I have run out of idea's any help would be most appreciated.
提前干杯.
推荐答案
不知道它是否对你的具体问题有帮助,但是如果你使用 initWithStyle:UITableViewCellStyleDefault
确实可以工作代码>
Don't know if it helps your specific problem, however UITextAlignmentCenter
does work if you use initWithStyle:UITableViewCellStyleDefault
这篇关于UITableViewCell中的文本居中对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell中的文本居中对齐问题


基础教程推荐
- :hover 状态不会在 iOS 上结束 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01