gpt4 book ai didi

ios - 更改角标(Badge)在 TDBadgedCell 中的位置

转载 作者:行者123 更新时间:2023-11-29 02:43:06 24 4
gpt4 key购买 nike

我是 Objective-C 开发的新手,目前正在开发我的第一个 iOS 应用程序。我想在 UITableView 单元格中显示角标(Badge)符号。为此,我找到了 TDBadgedCell Class on GitHub .我从 TDBadgedCell 派生了我自己的 UITableViewCell 类,基本上它工作正常。

我现在的问题是,我想更改角标(Badge)在单元格中的位置。我认为 api 不直接支持这一点,但我正试图找到一种方法来做到这一点。我试过单元格的 badge 属性,它是一个 UIView 对象,但它不起作用:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MCLThread *thread = self.threads[indexPath.row];
MCLThreadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ThreadCell" forIndexPath:indexPath];

cell.badgeString = thread.answerCount;

NSLog(@"Before: %f", cell.badge.frame.origin.y);

// Try to move badge
CGRect badgeFrame = cell.badge.frame;
badgeFrame.origin = CGPointMake(badgeFrame.origin.x, 35); // y = 35
cell.badge.frame = badgeFrame;

NSLog(@"After: %f", cell.badge.frame.origin.y);

return cell;
}

日志输出显示 y 坐标已更改,但角标(Badge)仍位于正在运行的应用程序中的相同位置。

2014-08-26 14:50:25.494 mclient[66574:60b] Before: 21.000000
2014-08-26 14:50:25.549 mclient[66574:60b] After: 35.000000

同样的方法对我有效,可以动态设置同一单元格中某些 UILabel 对象的位置(我已将其从上面的代码中删除)。

谁能告诉我这里有什么区别或者实现我的意图的正确方法是什么?

非常感谢!

最佳答案

抱歉,我没有正确阅读您的回答,这是我的建议编辑角标(Badge)框在 TDBadgedCell.m

- (void) layoutSubviews
{
[super layoutSubviews];

if(self.badgeString)
{
[[self contentView] addSubview:[self badge]];

// Force badges to hide on edit.
if(self.editing)
[self.badge setHidden:YES];
else
[self.badge setHidden:NO];

// Calculate the size of the bage from the badge string
UIFont *font = self.badge.boldFont ? [UIFont boldSystemFontOfSize:self.badge.fontSize] : [UIFont systemFontOfSize:self.badge.fontSize];

CGSize badgeSize;
if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
badgeSize = [self.badgeString sizeWithAttributes:@{ NSFontAttributeName:font }];
} else {
badgeSize = [self.badgeString sizeWithFont:font];
}

编辑这部分

//HERE STITCH EDIT ME PLEASE

CGRect badgeframe = CGRectMake(self.contentView.frame.size.width - (badgeSize.width + 13 + self.badgeRightOffset),
(CGFloat)round((self.contentView.frame.size.height - (badgeSize.height + (50/badgeSize.height))) / 2),
badgeSize.width + 13, badgeSize.height + (50/badgeSize.height));

关于ios - 更改角标(Badge)在 TDBadgedCell 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25506450/

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