forked from b051/RSMenuView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSMenuRightView.m
52 lines (43 loc) · 1.2 KB
/
RSMenuRightView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// RSMenuRightView.m
//
// Created by Rex Sheng on 10/16/12.
// Copyright (c) 2012 Log(n) LLC. All rights reserved.
//
#import "RSMenuRightView.h"
#import "RSMenuRightViewInfo.h"
NSString * const kRSMenuType = @"type";
NSString * const kRSMenuIdentifier = @"identifier";
@implementation RSMenuRightView
- (void)layoutSubviews
{
CGFloat x = self.bounds.size.width;
CGFloat h = self.bounds.size.height;
for (UIView *view in self.subviews) {
CGSize size = [view sizeThatFits:CGSizeZero];
x -= size.width;
size.height = h;
view.frame = CGRectMake(x, 0, size.width, size.height);
}
[super layoutSubviews];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
}
- (void)loadItems:(NSArray *)items
{
for (UIView *view in self.subviews) {
[view removeFromSuperview];
}
NSDictionary *item = nil;
NSEnumerator *enumerator = [items reverseObjectEnumerator];
while (item = [enumerator nextObject]) {
Class clazz = NSClassFromString(item[kRSMenuType]);
if ([clazz conformsToProtocol:@protocol(RSMenuRightViewInfo)]) {
NSString *identifier = item[kRSMenuIdentifier];
UIView *view = [[clazz alloc] initWithIdentifier:identifier attributes:item];
[self addSubview:view];
}
}
}
@end