forked from b051/RSMenuView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSMenuButton.m
40 lines (33 loc) · 1.17 KB
/
RSMenuButton.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
//
// RSMenuButton.m
//
// Created by Rex Sheng on 10/16/12.
// Copyright (c) 2012 Log(n) LLC. All rights reserved.
//
#import "RSMenuButton.h"
NSString * const RSMenuButtonClickedNotificationName = @"RSMenuButtonClickedNotification";
@interface RSMenuButton ()
@property (nonatomic, copy) NSString *identifier;
@end
@implementation RSMenuButton
- (id)initWithIdentifier:(NSString *)identifier attributes:(NSDictionary *)attributes
{
if (self = [super initWithFrame:CGRectZero]) {
self.identifier = identifier;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *icon = [UIImage imageNamed:attributes[@"image"]];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:icon forState:UIControlStateNormal];
self.frame = button.frame = CGRectMake(0, 0, MAX(icon.size.width, 26), icon.size.height);
button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self addSubview:button];
}
return self;
}
- (void)buttonClicked:(id)sender
{
if (_identifier) {
[[NSNotificationCenter defaultCenter] postNotificationName:RSMenuButtonClickedNotificationName object:_identifier];
}
}
@end