On the iPhone I like how action sheets take up the entire width of the screen and you can choose the height of it (so I can include other views). Here is my entire method that creates the action view (you probably on need the las few lines though)...
-(void)createActionView {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:#"Done",nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
UIButton *downHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
downHoleScore.frame = CGRectMake(93, 75, 35, 35);
[downHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
downHoleScore.backgroundColor = [UIColor clearColor];
downHoleScore.tag=1;
[downHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[downHoleScore setBackgroundImage:[UIImage imageNamed:#"Left-Down-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:downHoleScore];
UIButton *upHoleScore = [UIButton buttonWithType:UIButtonTypeCustom];
upHoleScore.frame = CGRectMake(193, 76, 35, 35);
[upHoleScore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
upHoleScore.backgroundColor = [UIColor clearColor];
upHoleScore.tag=2;
[upHoleScore addTarget:self action:#selector(HoleScoreButtonTap:) forControlEvents:UIControlEventTouchUpInside];
[upHoleScore setBackgroundImage:[UIImage imageNamed:#"Right-Up-Arrow.png"] forState:UIControlStateNormal];
[actionSheet addSubview:upHoleScore];
golferScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 70, 45, 45)];
golferScoreLabel.text = #"0";
golferScoreLabel.backgroundColor = [UIColor clearColor];
golferScoreLabel.font = [UIFont fontWithName:#"ChalkDuster" size: 45.0];
golferScoreLabel.textAlignment = UITextAlignmentCenter;
golferScoreLabel.shadowColor = [UIColor grayColor];
golferScoreLabel.shadowOffset = CGSizeMake(1,1);
golferScoreLabel.textColor = [UIColor whiteColor];
[actionSheet addSubview:golferScoreLabel];
CGRect pickerFrame = CGRectMake(0, 120, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
}
How would I edit this to make it look more like an action view on the iPhone?
In this code...
[actionSheet showFromRect:CGRectMake(0, 0, 320, 585) inView:self.view animated:YES];
That above is where I think I am messing up how would I make this cover the entire bottom half of the screen on the iPad?
Read the docs on UIActionSheet. On iPad, they are presented in popovers.
If you want behavior like on the iPhone, I think you'll have to write your own actionSheet-like view and animations (which is really not that hard, it just takes a little time).
Anyway, presenting actionSheets on an iPad with the full width wouldn't be very good design anyway - you probably don't want buttons that are as wide as the whole screen. I would advise you to rethink your design.
But maybe you don't really want actionSheets. Maybe you only want that nice animation, to present some content of your own like that? That's certainly doable (see above), but then you have asked the wrong question.
Related
I am developing one application for iphone and in that i have some issues regarding adding more then one UILabel in navigation bar at a specific position.
What i want is in following images
in above image there is one backbar button and one imageview as shown with arrow-mark. Other then that all white box is for difrent UILabels to show in navigation bar.
There is only one UIImageView in the navigation bar and one left bar button. Now problem is that i don't know how to add multiple UILabel in navigation bar at a specific position.
Till now what i have worked is to add only button and UIImageView with the right bar button array or left bar button array, but that only add items in sequnce.
So can anyone please guide me that how can anyone add UILabels or any other item at a specific position..
you can add Multiple UIlabel or Image as look like bellow image:-
this can do using bellow code you can change Label and imageView frame and put as your requirement
- (void)viewDidLoad
{
UIView *btn = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
UILabel *label;
label = [[UILabel alloc] initWithFrame:CGRectMake(5, 25, 200, 16)];
label.tag = 1;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = #"My first lable";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 200, 16)];
label.tag = 2;
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.adjustsFontSizeToFitWidth = NO;
label.textAlignment = UITextAlignmentRight;
label.textColor = [UIColor whiteColor];
label.text = #"second line";
label.highlightedTextColor = [UIColor whiteColor];
[btn addSubview:label];
[label release];
UIImageView *imgviw=[[UIImageView alloc]initWithFrame:CGRectMake(170, 10, 20, 20)];
imgviw.backgroundColor = [UIColor blackColor];
imgviw.image=[UIImage imageNamed:#"a59117c2eb511d911cbf62cf97a34d56.png"];
[btn addSubview:imgviw];
self.navigationItem.titleView = btn;
}
You can add subviews directly to the navigationBar -
UINavigationBar *navBar = navController.navigationBar;
[navBar addSubview: yourLabel];
yourLabel frame origin will be relative to the navigation bar
Try this code
UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
buttonContainer.backgroundColor = [UIColor clearColor];
UIButton *button0 = [UIButton buttonWithType:UIButtonTypeCustom];
[button0 setFrame: CGRectMake(160, 7 , 40, 30)];
[button0 setTitle:#"Sort" forState:UIControlStateNormal];
button0.titleLabel.font = [UIFont fontWithName:#"Helvetica" size:12];
[button0 setBackgroundImage:[UIImage imageNamed:#"Btn_Sort_Btn_Sort_Places.png"] forState:UIControlStateNormal];
[button0 addTarget:self action:#selector(sortAction) forControlEvents:UIControlEventTouchUpInside];
[button0 setShowsTouchWhenHighlighted:YES];
[buttonContainer addSubview:button0];
self.navigationItem.titleView = buttonContainer;
UILabel *lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(10, 0 , 140, 40)];
lbl_title.text = str_HeaderTitle;
lbl_title.textColor = [UIColor whiteColor];
lbl_title.font = [UIFont fontWithName:#"Helvetica-Bold" size:16];
lbl_title.backgroundColor = [UIColor clearColor];
lbl_title.textAlignment = NSTextAlignmentCenter;
[buttonContainer addSubview:lbl_title];
You can set an arbitrary view instead of a view controller's title:
myViewController.navigationItem.titleView = someView;
Note that most likely the view's frame will be restricted to make room for leftBarButtonItem and rightBarButtonItem.
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(50, 2, 20, 15)];
[label setBackgroundColor:[UIColor greenColor]];
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(40, 20, 150, 10)];
[imgView setBackgroundColor:[UIColor redColor]];
[[self.navigationController navigationBar] addSubview:label];
[self.navigationController.navigationBar addSubview:imgView];
Have a look at this piece of code. With some modifications it should solve your problem:
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:CGRectMake(15, 0, 57, 44)];
[imageButton setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 250, 44)];
[titleLabel setText:#"some title"];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[self.navigationController.navigationBar addSubview:imageButton];
[self.navigationController.navigationBar addSubview:titleLabel];
Just modify the values in the CGRectMake() to fit your needs.
I'm using the ZBar SDK to read QR codes on iPhone, however I added a button in that view. But the button is not working! Even i tap the button it doesn't go to the action method of that button. Where is the problem actually? Thanks in advance for the help.
-(UIView *)setSettingsButton
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[view setBackgroundColor:[UIColor clearColor]];
UIToolbar *myToolBar = [[UIToolbar alloc] init];
UIBarButtonItem *button=[[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStyleBordered target:self action:#selector(settingsAction)];
[myToolBar setItems:[NSArray arrayWithObjects:button,nil]];
settingsLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 37, 281, 77)];
[settingsLabel setFont:[UIFont fontWithName:#"Arial-BoldMT" size:16]];
[settingsLabel setTextAlignment:UITextAlignmentCenter];
[settingsLabel setBackgroundColor:[UIColor clearColor]];
[settingsLabel setTextColor:[UIColor blueColor]];
[settingsLabel setNumberOfLines:1];
[settingsLabel setText:#"For settings scan admin QR"];
[view addSubview:settingsLabel];
settingsLabel.hidden = YES;
[myToolBar setBarStyle:UIBarStyleDefault];
CGRect toolBarFrame;
toolBarFrame = CGRectMake(0, 436, 320, 44);
[myToolBar setFrame:toolBarFrame];
[view addSubview:myToolBar];
return view;
}
-(void)settingsAction
{
settingsLabel.hidden = NO;
}
I can't see where the problem is, but if it helps, I've customized zBar camera views without any problems.
The most likely answer is that a clear views is obscuring the tool-bar view. Here's a library for debugging UIViews: https://github.com/domesticcatsoftware/DCIntrospect
I had the same problem once. It was because my view was too big. Try to change the view's size like UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];, you'll see if it works.
I am attempting to add a UIToolbar to my cameraOverlayView for a custom imagePickerController. This is the code I want to use:
[self.imagePickerController.cameraOverlayView addSubview:self.topToolbar];
When trying to add a UIToolbar, nothing shows up. Encapsulating it into a UIView and setting it to the view property works if I use:
[self.imagePickerController.cameraOverlayView addSubview:self.view];
But this limits me to using one view for my overlay when I want to add several. I understand I can encapsulate everything into one big view, however when I do that, my bottom toolbar does not appear properly.
Has anyone had success in adding a UIToolbar as a subview to a cameraOverlayView?
i think you need a view to put all the things you need in your cameraOverlay.
for example:
TempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
TempView.alpha = 1.0;
anImageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#""]];
anImageView1.frame = CGRectMake(0, 0, anImageView1.image.size.width, anImageView1.image.size.height-50);
anImageView1.hidden = NO;
anImageView1.alpha = 1.0f;
tabBarHolder = [[UIImageView alloc]init];
tabBarHolder.backgroundColor = [UIColor blackColor];
tabBarHolder.frame = CGRectMake(0, 415, 320, 80);
tampBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 430, 35, 35)];
[tampBtn setBackgroundImage:[UIImage imageNamed:#"iconBack.png"] forState:UIControlStateNormal];
[tampBtn addTarget:self
action:#selector(xup)
forControlEvents:UIControlEventTouchUpInside];
ctampBtn = [[UIButton alloc] initWithFrame:CGRectMake(145, 430, 35, 35)];
[ctampBtn setBackgroundImage:[UIImage imageNamed:#"iconCamera.png"] forState:UIControlStateNormal];
[ctampBtn addTarget:self
action:#selector(takephoto)
forControlEvents:UIControlEventTouchUpInside];
[TempView addSubview:ctampBtn];
[TempView addSubview:tampBtn];
[TempView addSubview:anImageView1];
[TempView addSubview:tabBarHolder];
[TempView bringSubviewToFront:tabBarHolder];
[TempView bringSubviewToFront: ctampBtn];
[TempView bringSubviewToFront:tampBtn];
imagePicker.cameraOverlayView =TempView;
Hi I am doing a custom actionsheet in my application and I've noticed a small problem.
dismissal is ok but when doing the [actionSheet showInView:self.view],
the actionsheet animation does not start from the very bottom.
it appears from a good 200 pixels from the bottom before scrolling all the way up.
is this a known issue? i will paste my code below.
when doing a dismissal, it animates very smoothly from the top to the bottom.
Thanks in advance for any help !
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
datePickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[actionSheet addSubview:datePickerView];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 480)];
Remove this line:
[actionSheet setBounds:CGRectMake(0, 0, 320, 480)];
This is the code which is working fine.:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.backgroundColor = [UIColor clearColor];
UIImageView *background = [[UIImageView alloc] init];
[background setBackgroundColor:[UIColor whiteColor]];
[background setFrame:CGRectMake(0,0, 345, 250)];
background.contentMode = UIViewContentModeScaleToFill;
[actionSheet addSubview:background];
UIButton *cancelButton = [UIButton buttonWithType: UIButtonTypeCustom];
cancelButton.frame = CGRectMake(5, 160, 320, 100);
[cancelButton addTarget:self action:#selector(cancelButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
cancelButton.adjustsImageWhenHighlighted = YES;
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor colorWithRed:21/255.0f green:117/255.0f blue:222/255.0f alpha:1.0f] forState:UIControlStateNormal];
cancelButton.titleLabel.textAlignment = NSTextAlignmentCenter;
cancelButton.titleLabel.font = [UIFont fontWithName: #"Helvetica Neue" size: 22];
[actionSheet addSubview: cancelButton];
UIButton *airdropButton = [UIButton buttonWithType: UIButtonTypeCustom];
airdropButton.frame = CGRectMake(0,3, 100,80);
[airdropButton setImage:[UIImage imageNamed:#"airdrop.png"] forState:UIControlStateNormal];
airdropButton.adjustsImageWhenHighlighted = YES;
UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0,90,345,1)];
[line setBackgroundColor:[UIColor grayColor]];
UIButton *messageButton = [UIButton buttonWithType: UIButtonTypeCustom];
messageButton.frame = CGRectMake(10,95,80,80);
[messageButton setImage:[UIImage imageNamed:#"message.png"] forState:UIControlStateNormal];
messageButton.adjustsImageWhenHighlighted = YES;
UIButton *mailButton = [UIButton buttonWithType: UIButtonTypeCustom];
mailButton.frame = CGRectMake(80,95,100,80);
[mailButton setImage:[UIImage imageNamed:#"mail.png"] forState:UIControlStateNormal];
mailButton.adjustsImageWhenHighlighted = YES;
UIButton *twitterButton = [UIButton buttonWithType: UIButtonTypeCustom];
twitterButton.frame = CGRectMake(160,95,80,80);
[twitterButton setImage:[UIImage imageNamed:#"twitter.png"] forState:UIControlStateNormal];
twitterButton.adjustsImageWhenHighlighted = YES;
UIButton *facebookButton = [UIButton buttonWithType: UIButtonTypeCustom];
facebookButton.frame = CGRectMake(230,95,80,80);
[facebookButton setImage:[UIImage imageNamed:#"facebook.png"] forState:UIControlStateNormal];
facebookButton.adjustsImageWhenHighlighted = YES;
[actionSheet addSubview: airdropButton];
[actionSheet addSubview:line];
[actionSheet addSubview:messageButton];
[actionSheet addSubview:mailButton];
[actionSheet addSubview:facebookButton];
[actionSheet addSubview:twitterButton];
[actionSheet showInView:myProfileTable];
[actionSheet setFrame:CGRectMake(0,340,345,250)];
Look into this if you got any problem tell me.
I have created UIToolbar control.which is added as setInputAccessoryView to one UITextField Control.Which works fine. the tollbar comes up with uikeyboard when tapping UITextField.Up to this no issues.
When i placed one button, when tapping on it i want to hide the keyboard and only want to display the toolbar.
This is not happening.the toolbar is getting hidden.
Please let me know , what is the problem/ reason in the code.
Thanks for your time.
- (void)viewDidLoad {
[super viewDidLoad];
//
myToolbar = [[UIToolbar alloc] init];
[myToolbar sizeToFit];
myToolbar.frame = CGRectMake(0,198, 320, 35);
myToolbar.barStyle = UIBarStyleBlackTranslucent;
[self.view addSubview:myToolbar];
UIImage *image = [UIImage imageNamed:#"orangebuttonsmall.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(0, 100, image.size.width, 25 );
aButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[aButton setTitle:#"Tap" forState:UIControlStateNormal];
[aButton setBackgroundImage: image forState:UIControlStateNormal];
[aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
aButton.titleLabel.font = [UIFont boldSystemFontOfSize:10];
[aButton addTarget:self action:#selector(aCenterBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:aButton];
myToField = [[UITextField alloc] init];
myToField.frame = CGRectMake(0, 0, 320, 48);
myToField.textColor = [UIColor blackColor]; //text color
myToField.font = [UIFont systemFontOfSize:17.0]; //font size
myToField.placeholder = #"To:"; //place holder
myToField.backgroundColor = [UIColor whiteColor]; //background color
myToField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
myToField.keyboardType = UIKeyboardTypePhonePad; // type of the keyboard
myToField.returnKeyType = UIReturnKeyDone; // type of the return key
myToField.clearButtonMode = UITextFieldViewModeWhileEditing;
[myToField setInputAccessoryView:myToolbar];
myToField.textAlignment = UITextAlignmentLeft;
[myToField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
myToField.rightViewMode=UITextFieldViewModeAlways;
// has a clear 'x' button to the right
myToField.delegate = self;
[myToField becomeFirstResponder];
[self.view addSubview:myToField];
}
-(void)aCenterBtnClicked:(id)sender{
[myToField resignFirstResponder];
myToolbar.frame = CGRectMake(0,198, 320, 35);
myToolbar.barStyle = UIBarStyleBlackTranslucent;
[self.view addSubview:myToolbar];
}
inputAccessoryViews are placed as a subview on the UIKeyboard, if you hide the keyboard, it will hide the inputAccessoryView. Try adding the toolbar as a subview of self.view and animate it's position up when the keyboard is displayed by subscribing to the UIKeyboardWillShow notification and pulling the animation duration from the userInfo.
You try for static toolbar i think that will be easy for you.I am not done before remove from setinputview because there is no method for remove set input view.