非常有用的IOS KxMenu 仿微信

××××××××××××××××××××××××××××

转自:http://blog.csdn.net/jeepxiaozi/article/details/9002998

×××××××××××××××××××××××××××

首先,创建一个空的项目。

然后我们添加一个Object-C类,不添加xib文件。

之后我们把KxMenu类拷贝到我们的项目里,并且import进来。

再然后在我们自己的Obj-C类中添加一个UIButton,同时要把KxMenu初始化,我们来具体看下ViewController.m中的代码:

[cpp]  view plain copy
  1. #import "ViewController.h"  
  2. #import "KxMenu.h"  
  3.   
  4. @interface ViewController ()  
  5.   
  6. @end  
  7.   
  8. @implementation ViewController  
  9. {  
  10.     UIButton *_btn1;  
  11. }  
  12.   
  13. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  14. {  
  15.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  16.     if (self) {  
  17.         // Custom initialization  
  18.     }  
  19.     return self;  
  20. }  
  21.   
  22. -(void)loadView  
  23. {  
  24.     CGRect frame = [[UIScreen mainScreen] applicationFrame];  
  25.       
  26.     self.view = [[UIView alloc] initWithFrame:frame];  
  27.     self.view.backgroundColor = [UIColor whiteColor];  
  28.     self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;  
  29.       
  30.     _btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  31.     _btn1.frame = CGRectMake(5, 5, 100, 50);  
  32.     [_btn1 setTitle:@"KxMenu Test" forState:UIControlStateNormal];  
  33.     [_btn1 addTarget:self action:@selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];  
  34.     [self.view addSubview:_btn1];  
  35. }  
  36.   
  37. - (void)viewDidLoad  
  38. {  
  39.     [super viewDidLoad];  
  40.     // Do any additional setup after loading the view.  
  41. }  
  42.   
  43. - (void)didReceiveMemoryWarning  
  44. {  
  45.     [super didReceiveMemoryWarning];  
  46.     // Dispose of any resources that can be recreated.  
  47. }  
  48.   
  49. - (void)showMenu:(UIButton *)sender  
  50. {  
  51.     NSArray *menuItems =  
  52.     @[  
  53.         
  54.       [KxMenuItem menuItem:@"ACTION MENU Test"  
  55.                      image:nil  
  56.                     target:nil  
  57.                     action:NULL],  
  58.         
  59.       [KxMenuItem menuItem:@"Share this"  
  60.                      image:[UIImage imageNamed:@"action_icon"]  
  61.                     target:self  
  62.                     action:@selector(pushMenuItem:)],  
  63.         
  64.       [KxMenuItem menuItem:@"Check menu"  
  65.                      image:[UIImage imageNamed:@"check_icon"]  
  66.                     target:self  
  67.                     action:@selector(pushMenuItem:)],  
  68.         
  69.       [KxMenuItem menuItem:@"Reload page"  
  70.                      image:[UIImage imageNamed:@"reload"]  
  71.                     target:self  
  72.                     action:@selector(pushMenuItem:)],  
  73.         
  74.       [KxMenuItem menuItem:@"Search"  
  75.                      image:[UIImage imageNamed:@"search_icon"]  
  76.                     target:self  
  77.                     action:@selector(pushMenuItem:)],  
  78.         
  79.       [KxMenuItem menuItem:@"Go home"  
  80.                      image:[UIImage imageNamed:@"home_icon"]  
  81.                     target:self  
  82.                     action:@selector(pushMenuItem:)],  
  83.       ];  
  84.       
  85.     KxMenuItem *first = menuItems[0];  
  86.     first.foreColor = [UIColor colorWithRed:47/255.0f green:112/255.0f blue:225/255.0f alpha:1.0];  
  87.     first.alignment = NSTextAlignmentCenter;  
  88.       
  89.     [KxMenu showMenuInView:self.view  
  90.                   fromRect:sender.frame  
  91.                  menuItems:menuItems];  
  92. }  
  93.   
  94. - (void) pushMenuItem:(id)sender  
  95. {  
  96.     NSLog(@"%@", sender);  
  97. }  
  98. @end  
然后,我们要在ETAppDelegate.h中添加如下的代码:

[cpp]  view plain copy
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @class ViewController;//添加ViewController类  
  4.   
  5. @interface ETAppDelegate : UIResponder <UIApplicationDelegate>  
  6.   
  7. @property (strong, nonatomic) UIWindow *window;  
  8.   
  9. @property (strong, nonatomic) ViewController *viewController;//ViewController  
  10.   
  11. @end  
接下来我们就要在ETAppDelegate.m中加载我们自己的ViewController,导入ViewController.h

[cpp]  view plain copy
  1. #import "ViewController.h"  

然后修改application方法,如下:

[cpp]  view plain copy
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  4.     // Override point for customization after application launch.  
  5.     self.viewController = [[ViewController alloc] init];  
  6.     self.window.rootViewController = self.viewController;  
  7.     [self.window makeKeyAndVisible];  
  8.     return YES;  
  9. }  

OK,基本上初步试用的一个demo就完成了,下面是运行效果:

再次跪谢原作者的贡献,觉得这个效果再修改美化一下的话很通用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值