How to change button color on UIImagePickerControl

2019-04-24 09:19发布

I have managed to change the color of the navigation bar but the color of the buttons is still black. Is there any way to change the color of the buttons as well? See below image.

UPDATE: Sorry had to remove the image due to copy right issue.

10条回答
手持菜刀,她持情操
2楼-- · 2019-04-24 09:24

If you want to affect the color of the buttons that appear in all views such as the one you are hoping to change, then simply use the following:

UIBarButtonItem *searchBarButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[searchBarButton setTintColor:[UIColor colorWithRed:138.0/255.0 green:183.0/255.0 blue:64.0/255.0 alpha:1.0]];
查看更多
ゆ 、 Hurt°
3楼-- · 2019-04-24 09:27

You can achieve your desired customizations using the new UIAppearance APIs as of iOS 5 and onwards. This tutorial essentially shows you how.

查看更多
戒情不戒烟
4楼-- · 2019-04-24 09:31

@Ankit You can try getting the subviews from the navigation bar and then set the desired color . I used this approach to set the color of cancel button on the search bar . The size of the cancel button is 48*30 and you can use the subviews array to set the desired color. I am not sure but this may do the job . Below is the code i used to set the color of cancel button on the search bar.

NSArray *arrySearchSubviews=[searchBarFrnds subviews];
for (UIButton *btn in arrySearchSubviews) 
{
   CGRect rect=btn.frame;
    NSLog(@"width %f",rect.size.width);
    NSLog(@"height %f",rect.size.height);
    if (rect.size.width==48 ) 
    {
        [btn setTintColor:[UIColor colorWithRed:0 green:0.403f blue:0.4f alpha:1.0f]];
    }
}
查看更多
唯我独甜
5楼-- · 2019-04-24 09:32

You have to define a UIButtonTypeCustom button for your BarButtonItem.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIBarButtonItem *yourBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];

For more information, have a look at this post: UIBarButtonItem with color?

查看更多
SAY GOODBYE
6楼-- · 2019-04-24 09:39

I hope it will help you!

Step 1:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:NULL];

Step 2:

/* Status bar color */
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
/* Left button */
navigationController.navigationBar.tintColor = [UIColor blackColor];
/* Right button color  */
navigationController.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor blackColor];
查看更多
三岁会撩人
7楼-- · 2019-04-24 09:42

If you don't mind to use the same style across the whole app, use appearance as @Bourne suggested:

    let font = UIFont(name:"Montserrat-Bold", size:16)!
    let attributes: LTDictStrObj = [
        NSForegroundColorAttributeName: UIColor.whiteColor(),
        NSFontAttributeName: font,
    ]
    UIBarButtonItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal)

You can also change the background color of the navigation bar if you're using white color like me:

        picker.navigationBar.barTintColor = .redColor()
查看更多
登录 后发表回答