MacOS-NSDockTile: Set the red dot on the Dock icon, nsdocktiledock

Source: Internet
Author: User

MacOS-NSDockTile: Set the red dot on the Dock icon, nsdocktiledock
1. Set the dock icon

Through the code, we can dynamically set the Dock icon when the program is running. There are two ways to modify an icon:

Method 1: specify as an NSImage object
[NSApp setApplicationIconImage:[NSImage imageNamed:@"swift"]];
Method 2: Use a custom View to display it as the Dock icon

The custom View icon cannot be refreshed automatically. Therefore, if the Dock icon is changed, you may need to manually refresh it using the-display method when adding Badge.

NSImageView * imgView = [[NSImageView alloc] init]; imgView. frame = NSMakeRect (10, 10, 50, 50); imgView. imageFrameStyle = NSImageFramePhoto; // imgView of the image border. wantsLayer = YES; imgView. layer. backgroundColor = [NSColor cyanColor]. CGColor; imgView. image = [NSImage imageNamed: @ "swift"]; // imgView. imageScaling = NSImageScaleNone; [[NSApp dockTile] setContentView: imgView]; [[NSApp dockTile] display];

The program icons modified in the two methods described above will be restored to the application icons specified in Info. plist after the program exits.
To change the program icon permanently (that is, the modified icon can also be displayed when the program exits), you can create a plug-in for the Dock icon. This topic involves Bundle-related content and will not be detailed here.

2. Use NSDockTile to set the red dot on the Dock icon Add Badge

The configuration code is as follows:

NSDockTile *dock = [NSApp dockTile];if (dock) {    [dock setBadgeLabel:@"2"];    [dock setShowsApplicationBadge:YES];}

The system automatically sets the size according to the content of BadgeLabel, as follows:

Remove Badge

To remove Badge, set the content of badgeLabel to nil.

[[NSApp dockTile] setBadgeLabel:nil];
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.