In order to show a red point on the top right corner of a button,
Does any system method or third party could be used?
As a freshman , please tell me the detail code, thank you...
In order to show a red point on the top right corner of a button,
Does any system method or third party could be used?
As a freshman , please tell me the detail code, thank you...
With a quick search I would share the following github project too: https://github.com/szemian/DDBadgeViewCell
Using eg. the standard table management source code you can utilise DDBadgeViewCell like this:
- (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;
}
Please note that you set the badge information in cell.badgeText.
Source code from the example project.
for UIButton there is no system methods
but you can find custom classes on Github: https://github.com/search?l=Objective-C&q=Badge&ref=searchresults&type=Repositories
for example: https://github.com/ckteebe/CustomBadge
UPDATE:
// 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];
Code has been taken from CustomBadge example