UIActionSheet backGroundColor on iPad - objective-c

I'm struggeling with an issuse for quite a while now. Since I don't really find a solution, I hope somebody here will be able to help me.
I have a UIActionSheet that I want to have a different background color.
With
[[myAlert layer] setBackgroundColor:[UIColor redColor].CGColor];
I am able to change most of the alert's color.
This is how it looks like:
This is how I initialize the UIActionSheet:
UIActionSheet *styleAlert = [[UIActionSheet alloc] initWithTitle:AMLocalizedString(#"SELECT_PICTURE_TITLE", #"Überschrift des Actionsheets")
delegate:self
cancelButtonTitle:AMLocalizedString(#"CANCEL_BUTTON_TITLE", #"Abbrechen butten")
destructiveButtonTitle:nil
otherButtonTitles:AMLocalizedString(#"TAKE_PICTURE_BUTTON_TITLE", #"Bild aufnehmen button"),
AMLocalizedString(#"CAMERA_ROLL_BUTTON_TITLE", #"Aus Bibliothek auswählen"), nil];
// use the same style as the nav bar
[styleAlert showInView:self.parentViewController.tabBarController.view];
//[styleAlert showInView:[self.navigationController view] ];
[styleAlert release];
and
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
actionSheet.layer.backgroundColor = GLOBAL_TINT_COLOR.CGColor;
}
I could not figure out how to set the border with the same color. Any ideas?
Thanks in advance!

You can't redraw the border in a different color, so just remove the border and add your own:
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet {
UIView *contentView = actionSheet.superview;
UIView *popoverView = contentView.superview;
UIView *chromeView;
for (UIView *v in [popoverView subviews]) {
if (v.subviews.count == 3) {
chromeView = v;
break;
}
}
for (UIView *backgroundComponentView in [chromeView subviews]) {
backgroundComponentView.hidden = YES;
CGRect componentFrame = backgroundComponentView.frame; // add your view with this frame
}
}
Note that this won't work in *will*PresentActionSheet since actionSheet doesn't have a superview set at that point.

This works on iPhone to theme it, It will probably work on iPad also.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed#""]];
imageView.frame = CGRectMake(0, 0, actionSheet.frame.size.width, actionSheet.frame.size.height);
[actionSheet insertSubview:imageView atIndex:0];
NSArray *subviews = [actionSheet subviews];
for (UIView *v in subviews) {
if ([v isKindOfClass:[UIButton class]]) {
//Theme the buttons on the action sheet
UIButton *b = (UIButton *)v;
}
else if ([v isKindOfClass:[UILabel class]]) {
UILabel *l = (UILabel *)v;
//Theme the label at the top of the action sheet
}
}
}

Related

how to customize font size of button title of UIAlertController in IOS 8

How to change font size of button title of UIAlertController with UIActionSheet Style in IOS 8.
i have tried following function but this is not working for IOS8.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
for (UIView *_currentView in actionSheet.subviews) {
if ([_currentView isKindOfClass:[UILabel class]]) {
UILabel *l = [[UILabel alloc] initWithFrame:_currentView.frame];
l.text = [(UILabel *)_currentView text];
[l setFont:[UIFont fontWithName:#"Arial-BoldMT" size:20]];
[actionSheet addSubview:l];
_currentView.hidden = YES;
break;
}
}
}

cocoa detect object in mouse clicked

I created a custom object (NSImageView) to display images and I use addSubview: self.view to add
I want to determine if the mouse click in it.
How do I do?
Thank you.
NSImage *Image = [NSImage imageNamed:#"oneimage.jpg"];
NSImageView *ImageView = [[NSImageView alloc] init];
[ImageView setImage:Image];
[self.window addSubview:ImageView];
[ImageView_IconToAdd setAcceptsTouchEvents:YES];
[ImageView_IconToAdd setWantsRestingTouches:YES];
-(void)mouseDragged:(NSEvent *)theEvent {
id clickedObject = [self hitTest:[theEvent locationInWindow]];
if ([clickedObject isKindOfClass:[NSImageView class]]) {
NSLog(#"Clicked an ImageView");
} else if ([clickedObject isKindOfClass:[NSView class]]) {
NSLog(#"Clicked a WebView");
}
}
But error:
No visible #interface for 'WindowImage' declares the selector 'hitTest:'
And can't get Object!

Using ELCImagePickerController to select images

I am trying to use the ELCImagePickerController , and it works but i have a few things that i would like to change .
i want it to show me a matrix of images from the main album right away, without picking albums and stuff. just show a matrix, with a done button . now it lets you pick an album first .
i cant understand where exactly the picked images where saved ?
how can i change the buttons cancel and done graphics ?
this is how i add it (to cocos2d scene )
albumController = [[ELCAlbumPickerController alloc] initWithNibName:#"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];
[[[CCDirector sharedDirector] view] addSubview:elcPicker.view];
this is the done button :
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
//[self removeFromParentAndCleanup:YES];
for (UIView *v in [scrollview subviews])
{
[v removeFromSuperview];
}
CGRect workingFrame = scrollview.frame;
workingFrame.origin.x = 0;
for(NSDictionary *dict in info)
{
UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[scrollview addSubview:imageview];
[imageview release];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
}
[scrollview setPagingEnabled:YES];
[scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
}

UIImagePickerController how to hide the flip camera button?

is there a way to hide the flip camera button inside the UIImagePickerController?
thanks for reading
!^_^!
I ended up using a custom subclass of UIImagePickerController to fix this (and other) issues:
#import "SMImagePickerController.h"
#implementation SMImagePickerController
void hideFlipButtonInSubviews(UIView *view) {
if ([[[view class] description] isEqualToString:#"CAMFlipButton"]) {
[view setHidden:YES];
} else {
for (UIView *subview in [view subviews]) {
hideFlipButtonInSubviews(subview);
}
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
hideFlipButtonInSubviews(self.view);
}
#end
You should be able to create an empty button inside an overlayview that you float on top of the flip camera button. I hacked the code below to test and it seemed to work. Give it a try.
UIView *cameraOverlayView = [[UIView alloc] initWithFrame:CGRectMake(screenSize.width - 100.0f, 5.0f, 100.0f, 35.0f)];
[cameraOverlayView setBackgroundColor:[UIColor blackColor]];
UIButton *emptyBlackButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 35.0f)];
[emptyBlackButton setBackgroundColor:[UIColor blackColor]];
[emptyBlackButton setEnabled:YES];
[cameraOverlayView addSubview:emptyBlackButton];
cameraUI.allowsEditing = YES;
cameraUI.showsCameraControls = YES;
cameraUI.delegate = self;
cameraUI.cameraOverlayView = cameraOverlayView;

Add UIImageView as a subview to UIKeyboard - userInteractionEnabled?

I have a little problem with adding a subview to my UIKeyboard. I can successfully locate my keyboard and add an uiimageview to it, but unfortunately the button under the image view still can be touched. I just wanted to make it a color overlay, which would hide the unneeded keys and also make them untouchable :)
Here is my code, what am I doing wrong? The UIImageView displays correctly, but the buttons still can be tapped... :(
- (UIView *)findKeyboard {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIKeyboard.
UIView *foundKeyboard = nil;
for (UIView __strong *possibleKeyboard in [keyboardWindow subviews]) {
// iOS 4 sticks the UIKeyboard inside a UIPeripheralHostView.
if ([[possibleKeyboard description] hasPrefix:#"<UIPeripheralHostView"]) {
possibleKeyboard = [[possibleKeyboard subviews] objectAtIndex:0];
}
if ([[possibleKeyboard description] hasPrefix:#"<UIKeyboard"]) {
foundKeyboard = possibleKeyboard;
break;
}
}
return foundKeyboard;
}
- (void)keyboardWillShow:(NSNotification *)note {
UIImageView *overlayView;
UIView *keyboardView = [self findKeyboard];
UIImage *img = [UIImage imageNamed:#"keyboardOverlay.png"];
overlayView = [[UIImageView alloc] initWithImage:img];
[overlayView setUserInteractionEnabled:NO];
UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, overlayView.frame.size.width, overlayView.frame.size.height)];
newView.userInteractionEnabled = NO;
newView.multipleTouchEnabled = NO;
[newView addSubview:overlayView];
[keyboardView insertSubview:newView atIndex:40];
}
User interaction being disabled means that touches are passed straight through. Enable it, but don't have any gesture recognisers or actions, and it will swallow all touches.