I have a the following piece of code:
-(IBAction)routePicker
{
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 264, 320, 216)];
UIPickerView *thePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0,320,216)];
thePickerView.dataSource = self;
thePickerView.delegate = self;
[myView addSubview:thePickerView];
[self.view addSubview:myView];
}
this creates a subview of the UIPickerView, which contains predefined items I added.
At the moment this IBAction is linked to a custom button, so when I click on the button it loads the subview. I want to text box instead of a custom button. So when I click/tap on the text box my UIPickerView should load in the subview.
Regards,
Stephen
Check out this example from apple
Date Cell picker
Related
I m adding a UIView in UIActionSheet and I need to add four labels on the view and a close button.But I need the UIactionSheet to start from center of screen.When I m adhusting the dimensions I couldnot get it .
-(IBAction)buttontapped:(id)sender{
UIView *showDetailsView = [[UIView alloc]initWithFrame:CGRectMake(0,10, 320, 260)];
showDetailsView.backgroundColor = [UIColor whiteColor];
UILabel *name =[[UILabel alloc] init];
[name setFrame:CGRectMake(10, 40,250, 50)];
name.textAlignment = UITextAlignmentLeft;
name.backgroundColor = [UIColor clearColor];
name .font=[UIFont fontWithName:#"arial" size:12];
name.text=#"Name";
[showDetailsView addSubview:name];
UIActionSheet *aac = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Close", nil];
aac.actionSheetStyle = UIActionSheetStyleAutomatic;
[aac addSubview:showDetailsView];
[aac setFrame:CGRectMake(0,0,320,400)];
[aac showInView:self.view];
}
I can see it added from the bottom but it is not expanding to the center of screen like in the following figure:I need to increase its height.
From one of the SO's answer I get this method and it's works like charm :)
-(void)setActionSheetHeight
{
CGRect actionSheetRect = self.myActionSheet.frame;
CGFloat orgHeight = actionSheetRect.size.height;
actionSheetRect.origin.y -= 214; //height of picker
actionSheetRect.size.height = orgHeight+214;
self.myActionSheet.frame = actionSheetRect;
[self.myPicker setShowsSelectionIndicator:YES];
CGRect pickerRect = self.myPicker.frame;
pickerRect.origin.y = orgHeight;
self.myPicker.frame = pickerRect;
}
Here myActionSheet is one UIActionSheet iVar.
Here myPicker is one UIPickerView iVar.
Instead of 214 static value you can set your desired value and according to that it will set the height of the UIActionSheet.
NOTE
Must be called after the action sheet is shown ie after the [self.myActionSheet showFromTabBar:self.tabBarController.tabBar]; kind of line of code. Means after call the show method on action sheet.
Use this:
[aac setBounds:CGRectMake(0,0,320,400)];
UIActionSheet is designed to be presented from the bottom of the screen.
You can display it in center on ipad only..not in iphone.
You can use custom Alertview for your requirement.
https://github.com/alokard/BlockAlertView
When you present the actionsheet, you need to send appropriate message to present it. Refer to
showFromRect:inView:animated:
showInView:
For showInView:, you can have an invisible view with the bottom at mid-height of the view controller and top aligned to the top of viewcontroller.
For showFromRect:inView:animated:, if you have any UIView to which the actionsheet needs to be anchored, you can used it there.
I have a full screen UIScrollView to display my image. An UIActivityIndicatorView is added to the UIScrollView, it spinning well, but how could i make it always spinning in the middle of the screen while I am scrolling, zooming, rotating?
If you add the UIActivityIndicatorView directly to the scroll view it will scroll with the scroll view. But, if you add it to the parent of the scroll view it will remain where it was placed. So, the solution is to add it to the parent of the scroll view.
Notes:
I would recommend having a UIViewController in your window, and then adding these both to the UIViewController.
See the discussion here about adding views directly to your window:
View Controller being sent a message even though it has been deallocated
In ur .h file
UIView *primaryImage;
UIView *secondaryImage;
UIActivityIndicatorView *indicator;
In ur .m file
-(void)indicatorView
{
primaryImage = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
primaryImage.backgroundColor = [UIColor blackColor];
primaryImage.alpha =0.5;
//[self.view.superview insertSubview:primaryImage aboveSubview:self.view.superview];
//[theTableView addSubview:primaryImage];
[self.view addSubview:primaryImage];
secondaryImage = [[UIView alloc] initWithFrame:CGRectMake(127.50,215,65,50)];
secondaryImage.backgroundColor = [UIColor blackColor];
secondaryImage.alpha = 0.9;
secondaryImage.layer.cornerRadius = 12;
[primaryImage addSubview:secondaryImage];
indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30, 25, 25, 25)];
indicator.center = CGPointMake(32, 25);
//[indicator hidesWhenStopped];
[indicator startAnimating];
[secondaryImage addSubview:indicator];
}
-(void)dismissCoverImageView {
[indicator stopAnimating];
[indicator removeFromSuperview];
[secondaryImage removeFromSuperview];
[primaryImage removeFromSuperview];
}
and after that you can call [self indicatorView];
and [self dismissCoverImageView];
Define the UIScrollViewDelegate of your UIScrollView. And in the delegate method –(void)scrollViewDidScroll:(UIScrollView *)scrollView change the frame of UIActivityIndicator object.
Check out the Facebook app. When you click on All Stories in the navbar it slides up a UIPickerView ontop of their UITableView.
I would like to simulate this same behavior in my app. How can I slide up a UIPickerView like this?
Update:
This is how I am creating my PickerView:
CGRect pickerFrame = CGRectMake(0, 320, 320, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[[[UIApplication sharedApplication] keyWindow] addSubview:pickerView];
Id like to animate it from the bottom of the screen up.
My guess is that they are just creating a uiview off of the bottom of the screen with a uipicker... then animating the frame's Y up.
UPDATE:
In fact, the UIPickerView is just a UIView so you wouldn't even need to have a wrapper UIView... just add the picker as the top view of your window with the top of its frame just below the bottom of the window.
- (void)loadView
{
SettingsTitleBar=[[UINavigationController alloc] initWithRootViewController: self];
searchBar =[ [UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 40)];
searchBar.placeholder = #"Type your City Name";
searchBar.delegate = self;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
[searchBar setShowsCancelButton:YES];
[SettingsTitleBar.navigationBar addSubview:searchBar];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 85, 320, 392)];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 120, 320, 302) style: UITableViewStyleGrouped];
[tableView setDelegate:self];
[tableView setDataSource:self];
[self.view addSubview:tableView];
}
I Have a UITableViewController,
I have utilized the first 44 pixels height for title bar, and then the next 40 pixels of height for search bar(44+40). These are added as navigation controller subviews. then i am adding my self.view at 85 pixel from top, finally tableview has been added as child to the self.view . But table view has been overlapped with the Searchbar. I dont what is wrong with it. I tried to change various yPositions of tableview and self.view but still nothing happened.
Can anyone able to help me out from this ?
Note : I dont want to add SearchBar into UITableviewHeader Section.
U can make the view of size 320X436 and add the tabble view and search bar in that view...
I wouldn't add subviews to the navigationBar. Add it to the view.
As a sidenote: anything you alloc (or retain or copy), you should release or autorelease
I had trouble with this too, initially. Don't worry about adding the searchBar as a subview. Simply do this:
self.tableView.tableHeaderView = searchBar;
The searchBar will be treated like a header. You'll want to change the CGRect's size to (0,0,320,44), however.
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0),
kTopPlacement, kImageWidth, kImageHeight);
self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease];
[self.view addSubview:self.containerView];
// create the initial image view
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.mainView.image = [UIImage imageNamed:imagePath];
I want to put a button inside mainview.image. How can I do it?
Any help will be greatly appreciated.
you have to create one button.
and add mainView as a subview to that button using code:
[btnButton addSubView:mainView];
and add this button as a subview to your ViewContoller 's view
[self.view addSubView:btnButton];
Might be easier to use a UIButton and add the image as the background.
Look at the section on Configuring Button With Images
You could also add a clear button (using the UIButtonTypeCustom) on top of the UIImageView if you want the button to only take up part of the image.