Customise the appearance of UIActivityViewController - ios

Is it possible to customise the following items in the UIActivityViewController?
background (I want it to be flat white)
icons of default items
the cancel button
If I iterate over the subviews none of them seems to be public, so it might be problematic with the approval even if I succeed to change them: UIActivityListView, UIActivityCancelButton
I saw some custom activity controllers but the amount of dependencies put me off immediately.
Thanks.

You can get at some of those with UIAppearance. The cancel button is probably the easiest. The background color works, but it shows over the entire screen. There might be a better way to do that. The icons probably can't be customised.
It's likely that you'll be able to customise some of it but not all. And doing that is probably worse than just leaving the default.
[[UIView appearanceWhenContainedIn:[UIActivityViewController class], nil] setBackgroundColor:[UIColor redColor]];
[[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];

socialActivityPopover = [[UIPopoverController alloc] initWithContentViewController:activityView];
[socialActivityPopover setBackgroundColor:[UIColor redColor]];

Related

Set the background color of my buttons excluding accessory buttons

I'm trying to globally change the color of my buttons, but I'm struggling with one in particular. I have a UITableView which in its cells I put an UITableViewCellAccessory. This is contained in a UIViewController and below this I have a UIStackView with a button inside, this is the one I want to change the background color.
I've trying
[[UIButton appearanceWhenContainedIn:[MyClass class], nil] setBackground:myColor];
But the problem is that it also paints the accessory
Also something like
[UIButton appearanceWhenContainedInInstancesOfClasses:#[[MyClass class], [UIViewController class], [UIStackView class]]] setBackground:myColor];
this one does nothing
Is there anything else I can try to achieve this?

UIButton appearance setBackgroundColor effecting navigation bar now after update

Xcode or iOS update has made the following code below function differently because now the navigation bar button background has a background color, unlike previously. Any fix? I want all buttons to have the same global color, but now it effects the navigation bar buttons which I dont want. I would like it transparent like before.
[[UIButton appearance] setBackgroundColor:[Helper getColor:self.application.color]];
As this particular UIButton is inside a UINavigationBar you could try applying a second specific appearance to 'override' the first general appearance set.
For example calling specifically,
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil]
setBackgroundColor:[UIColor clearColor] forState:state barMetrics:metrics];
after you call,
[[UIButton appearance] setBackgroundColor:[Helper getColor:self.application.color]];
To override the general with the specific.
Docs Link: https://developer.apple.com/documentation/uikit/uiappearance

UISegmentedControl, rightBarButtonItem and rotation issues

I'm trying to recreate (to some extent) the up and down arrows presented on Mail.app on iOS 7 and iOS 8. There's not much to it. I just insert a UISegmentedControl into a UIBarButtonItem, like this (if you do know a better way of replicating that UI, please let me know):
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:#[[UIImage imageNamed:#"ArrowDown"], [UIImage imageNamed:#"ArrowUp"]]];
[segmentedControl addTarget:self action:#selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
[segmentedControl setBackgroundImage:[[UIImage alloc] init] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentedControl setDividerImage:[[UIImage alloc] init] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentedControl setFrame:CGRectMake(0, 0, 100, 30)];
[segmentedControl setMomentary:YES];
UIBarButtonItem *segmentedButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.rightBarButtonItem = segmentedButton;
Notice the calls to setBackgroundImage: and setDividerImage:. They are needed so the control looks just like the one from Mail.app. And that setup works:
Trouble is, it doesn't stay that way after a rotation. When using the iPhone in landscape, the rightBarButtonItem is automatically resized, looking broken and staying that way even after returning the device to portrait mode:
The control still works as planned , but well... It doesn't look so pretty anymore.
I have experimented with lots of properties and different setups, and nothing seems to work, except not setting an empty UIImage for the control background. If I comment out the setBackgroundImage: and the setDividerImage: pieces of code, the control keeps its look even after rotating:
But that's not the UI I have been looking for.
Do you know of any way to achieve the intended look and still have the correct behavior around? Or even what could be causing the resizing in the first place?
You may try to use two UIButton instead to UISegmentControl.
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
self.navigationItem.rightBarButtonItem = rightItem;

UIAlertview valueForKey:#"_backgroundImageView"

I want to change the text color and background color of ui alert view. I was using the following code,
UILabel *theTitle = [alertView valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor whiteColor]];
UILabel *theBody = [alertView valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor whiteColor]];
UIImageView *backgroundImageView = (UIImageView *)[alertView valueForKey:#"_backgroundImageView"];
[backgroundImageView setImage:[UIImage imageNamed:#"background.png"]];
this was working fine in ios 6. But after upgrading to ios 7, this method is not working. I dont want to create custom uialertview. Please suggest any simple solution to fix this.
Starting in iOS7, UIAlertViews are not customizable anymore.
You'll have to stick to their style, or create your own from a UIView, but you cannot change that.
In iOS7, UIAlertView is nothing but a data container. It just takes the parameters you set and displays them in a private view hierarchy on a private window. Your alert view is never added to any view hierarchy.
Either roll your own alert view implementation or use an open source one, like DTAlertView: https://www.cocoacontrols.com/controls/dtalertview

How do you set the background color of a UINavigationbar programatically?

I am using a cocoa iOS component from cocoacontrols.com, which is NOT using storyboards. This class creates a new modal view and the modal view has a NavigationBar at the top. I am trying to get the color of the navigationBar to change. In all my other views, which are storyboard based, I use a base class of STBaseViewController which sets the navigationBar as white.
I have changed this cocoacontrol class to be a STBaseViewController instead of a UIViewController, but it still is not changing my background to white.
#interface BZPasscodeFieldController : STBaseViewController
In the BZPasscodeFieldController, which they don't make any reference to a navigationbar, so I am not sure how its even showing up (again it has no storyboard's only xibs and they don't have navigationbars)?
Anyway, does anyone know how to make the navigationbar background color white programatically?
Further, in all my storyboard viewControllers that have a UINavigationBar, I have added a UIButton over the area where the title goes, so that I can easily change the font/style and also make it clickable. I need to add this same UIButton to the uinavigationBar of this BZPasscodeFieldController created programatically. How would I go about doing that?
To Set Navigationbar Background Color:
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
To set Navigationbar Tint Color:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
For your question about the button on the place of title of navigationBar. Each navigationBar has a titleView property, you can assign any view to it. For example take a look at this method, you can call it in your BZPasscodeFieldController:
- (void) setNavigationBarTitleButton
{
UIButton* centralButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 44)];
[centralButton setImage:navigationCentralButtonImage forState:UIControlStateNormal];
[centralButton setShowsTouchWhenHighlighted:TRUE];
[centralButton addTarget:self action:#selector(goHigher) forControlEvents:UIControlEventTouchDown];
self.navigationItem.titleView = centralButton;
}
For your previous question the answers provided already are all correct, calling them in the right place(for example in AppDelegate's application:didFinishLaunchingWithOptions: should make it work well, unless something is messed up in your custom view controller classes.
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

Resources