UIBarButtonItem with rounded corners and shadow

后端 未结 5 1480
灰色年华
灰色年华 2021-01-04 23:44

I want to have rounded corners and shadow on a UIBarButtonItem.

UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
相关标签:
5条回答
  • 2021-01-05 00:16
    buttonName.layer.cornerRadius = 2;
    buttonName.layer.borderWidth = 1;
    buttonName.layer.borderColor = [UIColor blacColor].CGColor;
    
    0 讨论(0)
  • 2021-01-05 00:17
        UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
        useButton.frame = CGRectMake(0, 0, 60, 30);
        useButton.backgroundColor = [UIColor redColor];
        useButton.layer.masksToBounds = NO;
        useButton.layer.cornerRadius = 4;
        useButton.layer.shadowOffset = CGSizeMake(0, 1.5);
        useButton.layer.shadowRadius = 5;
        useButton.layer.shadowOpacity = 1.0;
    //    useButton.layer.shadowColor = [UIColor blackColor].CGColor;
        useButton.layer.borderColor = [UIColor blackColor].CGColor;
        [self.view addSubview:useButton];
    
        UIBarButtonItem *useItem = [[UIBarButtonItem alloc] initWithCustomView:useButton];
        [self.navigationItem setRightBarButtonItems:@[useItem]];
    
    0 讨论(0)
  • 2021-01-05 00:21

    Try this Updated code :

    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]];
    
    0 讨论(0)
  • 2021-01-05 00:23
    btn.layer.cornerRadius = 2.0 ;
    
    0 讨论(0)
  • 2021-01-05 00:25
    btnname.layer.cornerRadius = 8.0;
    btnname.layer.shadowOffset = CGSizeMake(2, 2);
    
    0 讨论(0)
提交回复
热议问题