且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有圆角和阴影的 UIBarButtonItem

更新时间:2021-07-14 22:08:05

试试这个更新的代码:

UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
useButton.frame = CGRectMake(100, 430, 100, 40);
useButton.layer.masksToBounds = NO;
useButton.layer.cornerRadius = 10;
useButton.layer.shadowOffset = CGSizeMake(1.5, 1.5);
useButton.layer.shadowRadius = 0.5;
useButton.layer.shadowOpacity = 1.0;
useButton.layer.shadowColor = [UIColor blackColor].CGColor;
useButton.backgroundColor = [UIColor redColor];

UIBarButtonItem *useItem = [[UIBarButtonItem alloc] initWithCustomView:useButton];
[self.navigationItem setRightBarButtonItems:@[useItem]];