ios nav自定义button
Posted 人生路1/5
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios nav自定义button相关的知识,希望对你有一定的参考价值。
+(void)initialize{ UINavigationBar *item = [UINavigationBar appearance]; // 按钮的颜色 item.tintColor = [UIColor redColor]; // 整个背景的颜色 item.barTintColor = [UIColor orangeColor]; }
NSMutableDictionary *dic = [NSMutableDictionary dictionary]; dic[NSForegroundColorAttributeName] = [UIColor whiteColor]; UINavigationBar *item = [UINavigationBar appearance]; [item setTitleTextAttributes:dic]; [item setBackgroundImage:[UIImage imageNamed:@"top"] forBarMetrics:UIBarMetricsDefault];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:@"back_hover"] forState:UIControlStateSelected]; [btn setTitle:@"返回" forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:15]; [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; btn.size = CGSizeMake(50, 29); // btn.backgroundColor = [UIColor lightGrayColor]; // btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; // btn.contentEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0); [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
以上是关于ios nav自定义button的主要内容,如果未能解决你的问题,请参考以下文章