一直有在用那个屏保WordClock很喜欢,看到有人用安卓做了一个。iOS版的没有比较合适的,所以就写了这个Demo。但是iPhone的壁纸不能像安卓那么强大,网上给的方案用3D Touch的Live Photo也有点蠢,所以这块暂时没什么办法。
实例化BSHWordClockView,实现其代理方法。
self.wordClock = [[BSHWordClockView alloc] initWithFrame:t];
self.wordClock.center = self.view.center;
self.wordClock.delegate = self;
self.wordClock.dataSource = self;
[self.view addSubview:self.wordClock];
#pragma mark - BSHWordDataSource
- (NSInteger)numberOfWordClockItemsIn:(NSInteger)section {
return [self.sourceArray[section] count];
}
- (NSInteger)numberOfWordClockSections {
return self.sourceArray.count;
}
- (NSString *)wordClockTextSection:(NSInteger)section andIndex:(NSInteger)index {
NSArray *a = self.sourceArray[section];
return a[index];
}
- (__kindof UIView *)wordItemViewForIndex:(NSInteger)index section:(NSInteger)section {
BSHWordItemLabel *label = [[BSHWordItemLabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor blackColor];
label.font = [UIFont systemFontOfSize:8];
label.textAlignment = NSTextAlignmentRight;
return label;
}
持有坐标和形变的model
持有BSHWordClockLayoutAttribute的Label
为了便于维护和扩展,时钟的主View设计成API和TableView类似。
要求代理必须实现。
待扩展的协议。
- 文本自定义
- 按秒定时更新
- 流式布局和环形布局简单切换
- 流式布局和环形布局仿WordClock切换动画
- 支持手势滑动