UIAlertview valueForKey:#"_backgroundImageView" - ios

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

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?

Trying to show an activity indicator in a custom cell in iOS 7

I had a custom cell defined in a xib file where I later place an UIActivityIndicatorView programmatically in a view controller. This was correctly working for iOS 6 and earlier, but I'm not able to see the activity indicator in iOS 7.
I'm doing this way: I firstly register the nib in the view controller's viewDidLoad
[self.tableView registerNib:[UINib nibWithNibName:#"CustomCell" bundle:nil] forCellReuseIdentifier:#"customCell"];
Then, in cellForRowAtIndexPath: and if system version is 7.0 or above, I do:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(259, 21, activityIndicator.frame.size.width, activityIndicator.frame.size.height);
[cell.contentView addSubview:activityIndicator];
But, as I said, the activity indicator is not shown. Subviews in iOS7 are supposed to be added to cell's contentView, am I missing anything else?
Thanks
Try with this, change the activity indicator color as clear color before animating.
[self.activityIndicator setBackgroundColor:[UIColor clearColor]];
[self.activityIndicator startAnimating];
Even its not working,then try to uncheck Animating behavior in attributes inspector in IB
i belive you have created cell by using interface builder i.e "Customcell" in your case. but added activity indicator by coding in "cellForRowAtIndexPath" which is wrong. Try creating activity indicator using interface builder which is easy and hide it if necessary in "cellForRowAtIndexPath"
Use [cell.contentView.view addSubview:activityIndicator] instead.

Customise the appearance of UIActivityViewController

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]];

iOS set background color for all viewcontroller self.view's

Is there a way to set same background image for all views?
Setting same background in all viewDidLoad: methods. It's not cool.
You can create a custom class, let's call it a TemplateView, which is subclass of UIView.
Then using xib/storyboards select the controller view and identity inspector change the Class property to 'TemplateView'.
Subsequently using an UIAppearance change the background color of the template view to the desired one.
[[TemplateView appearance]setBackgroundColor:[UIColor blueColor]];
That will change the background color of each of the template views in your project.
I think it's better solution than
[[UIView appearance] setBackgroundColor:[UIColor redColor]];
because we don't change the background of everything, just our custom class.
Hope it will help.
Yes, using UIAppearance in iOS5+:
[[UIView appearance] setBackgroundColor:[UIColor redColor]];
NOTE: UIView conforms to <UIAppearance, UIAppearanceContainer> protocols but does not mark any properties as UI_APPEARANCE_SELECTOR for some reason.
I don't think this is a good idea, but if you really want to do this, you could do something like this:
- (void)setBGColor:(UIColor *)color forAllSubviewsOf:(UIView *)view
{
[view setBackgroundColor:color];
for (UIView *sub in view.subviews)
[self setBGColor:color forAllSubviewsOf:sub];
}
I guess you can use Method Swizzling kind some feature to change all views colour or image setting.
Check following
https://wiredcraft.com/blog/method-swizzling-ios/

iOS accessibility - How do you set the accessibility label for the title of a UINavigationBar?

Apple's voice over mispronounces the title of one of my views, which is inside a UINavigation Controller.
In other parts of the app I have added a custom accessibility label to help it pronounce the company name correctly. How can I set the accessibility label of a UINavigationBar?
This works in iOS 8.2. In viewDidLoad:
self.navigationItem.accessibilityLabel = #"My accessible label";
When a navigation controller transitions to the view controller, the accessibilityLabel is read instead of the view controller title.
I couldn't add an accessibility label, but I found a workaround:
I replace the navigationItem's title View with a UILabel that has accessibility set up.
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = #"myTitle";
[titleLabel setAccessibilityLabel:#"myCustomAccessiblityLabel"];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20.0]];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel sizeToFit];
self.navigationItem.titleView = titleLabel;
I'm not sure why setting the accessibility label doesn't work, but the above code works for my needs.
Since UINavigationBar inherits from UIView, you should be able to set its accessibilityLabel property. Try: yourUINavigationBar.accessibilityLabel = #"title";.
Also, you may need to ensure sure it is marked as an accessibility element with yourUINavigationBar.isAccessibilityElement = YES; (and is not inside another view which is also marked as an accessibility element). (I'm guessing this last bit may be the issue, since it appears that you already knew about accessibility labels. You can use the Accessibility Inspector in the simulator to see if this is the case by looking at the box around the element when you tap it to see if it's around something bigger than the navigator bar.)
There a similar workaround which I have tested on iOS 11 and 12 that works as expected. For the navigationItem.titleView set a UILabel object and then set your accessibility identifier for the navigationItem.titleView.
self.navigationItem.titleView = YOUR_CUSTOM_UILABEL;
accessibilityIdentifier part
self.navigationItem.titleView.accessibilityIdentifier = YOUR_ACCESSIBILITY_IDENTIFIER;
You can see your identifier with using Xcode's Accessibility Inspector.

Resources