为了在按钮的右上角显示红点,
是否可以使用任何系统方法或第三方?
作为新生,请告诉我详细代码,谢谢......
答案 0 :(得分:1)
通过快速搜索,我也会分享以下github项目:https://github.com/szemian/DDBadgeViewCell
使用例如。您可以使用DDBadgeViewCell的标准表管理源代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
DDBadgeViewCell *cell = (DDBadgeViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[DDBadgeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.summary = @"Summary";
cell.detail = @"Detail text goes here";
cell.badgeText = [NSString stringWithFormat:@"Row %d", indexPath.row];
cell.badgeColor = [UIColor orangeColor];
return cell;
}
请注意,您在cell.badgeText
。
示例项目的源代码。
答案 1 :(得分:0)
对于UIButton
,没有系统方法
但您可以在Github上找到自定义类:https://github.com/search?l=Objective-C&q=Badge&ref=searchresults&type=Repositories
例如:https://github.com/ckteebe/CustomBadge
<强>更新强>
// Create simple Badge
CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"
withStringColor:[UIColor whiteColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:YES];
// Set Position of Badge 1
[customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+customBadge2.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)];
// Add Badges to View
[self.view addSubview:customBadge2];
代码取自CustomBadge
示例