Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keith/kslabel
A drop in subclass of NSTextField for programmatically created labels.
https://github.com/keith/kslabel
Last synced: about 1 month ago
JSON representation
A drop in subclass of NSTextField for programmatically created labels.
- Host: GitHub
- URL: https://github.com/keith/kslabel
- Owner: keith
- License: mit
- Created: 2012-11-15T20:58:51.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-02-14T06:44:20.000Z (over 9 years ago)
- Last Synced: 2024-10-10T16:37:27.939Z (about 1 month ago)
- Language: Objective-C
- Size: 164 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## KSLabel
A dead simple class for when you need to create a simple label
programmatically.## Methods
The only custom method available is
```objc
- (instancetype)initWithAttributedString:(NSAttributedString *)string
inView:(NSView *)view;
```The attributed string should be an `NSAttributedString` with whatever
attributes you want to be displayed. **Be sure to set the
`NSFontAttributeName` key**The passed `NSView` should be the view the label will be added to. The
label will be setup to be centered within the passed view.You can also set `notificationToPost` with the name of an
`NSNotification` to be posted when the label is clicked.Example:
```objc
NSDictionary *attributes = @{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]]};
NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"My string"
attributes:attributes];
KSLabel *mylabel = [[KSLabel alloc] initWithAttributedString:string
inView:titleBarView];
mylabel.notificationToPost = @"Some String!";
NSNotification *notification = [NSNotification notificationWithName:@"someName"
object:someObject
userInfo:@{@"someKey": @"someObject"}]
myLabel.NSNotificationToPost = notification;
myLabel.action = @selector(doSomething:);
myLabel.cursor = [NSCursor pointingHandCursor];
[myView addSubview:mylabel];
```## [CocoaPods](http://cocoapods.org/)
If you're using CocoaPods, which you should be, just add this to your
Podfile.pod 'KSLabel'