适用于任何 Objective-C 项目,包括今天的小部件和 Apple Watch (WatchKit) 应用程序扩展。
导入头文件
#import <WeightedWordCloud/HITWeightedWordCloud.h>
创建并配置一个 HITWeightedWordCloud 对象。您可以在 (void)awakeWithContext:(id)context
中完成此操作。
self.wordCloud = [HITWeightedWordCloud.alloc initWithSize:CGSizeMake(CGRectGetWidth(self.contentFrame), CGRectGetHeight(self.contentFrame)];
self.wordCloud.textColor = UIColor.whiteColor;
self.wordCloud.scale = WKInterfaceDevice.currentDevice.screenScale;
设置数据并渲染词云。字典键是您的单词,值是权重。权重控制渲染云中单词的字体大小。
NSDictionary *wordsDictionary = @{@"Very important": @500,
@"Still important": @400,
@"Less important": @100,
@"Not important at all": @0};
[self.imageView setImage:[self.wordCloud imageWithWords:wordsDictionary]];
查看头文件了解更多选项。
WeightedWordCloud 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile 中
pod 'WeightedWordCloud', '0.1.0'
Maciej Swic, [email protected]
WeightedWordCloud 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。