I am working on a project where I am using custom buttons for login and signup.
All I want is when I click on login, the color of signup button changes and when I click on signup button again the color of login button changs back.
I tried the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
// [self.view setNuiClass:#"ViewInit"];
// Do any additional setup after loading the view from its nib.
UIImageView *img = [[UIImageView alloc ] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
img.image = [UIImage imageNamed:#"iphone-4-apple-logo-wallpapers-set-2-05.jpg"];
[self.view addSubview:img];
NSLog(#"Height Pro %f",[[DeviceClass instance] getResizeScreen:NO].size.height);
scrollView = [[UIScrollView alloc] initWithFrame:[[DeviceClass instance] getResizeScreen:NO]];
scrollView.alwaysBounceVertical = YES;
scrollView.delegate = self;
[self.view addSubview:scrollView];
segmentControl = [[UISegmentedControl alloc] initWithItems:#[NSLocalizedString(#"profile_tab_signin", nil),NSLocalizedString(#"profile_tab_signup", nil)]];
segmentControl.frame = CGRectMake(10, 10, 300, 40);
segmentControl.selectedSegmentIndex = 0;
[segmentControl addTarget:self action:#selector(valueChanged) forControlEvents: UIControlEventValueChanged];
[scrollView addSubview:segmentControl];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTap];
//Init
[self autoLogin];
[self.view setNeedsDisplay];
//[signUpBtn setBackgroundColor:[UIColor redColor]];
//[loginBtn setBackgroundColor:[UIColor yellowColor]];
}
- (void)valueChanged
{
//For SignIn/SignUp
if(segmentControl.selectedSegmentIndex == 0)
{
[usernameSignUp removeFromSuperview];
[emailSignUp removeFromSuperview];
[firstNameSignUp removeFromSuperview];
[lastNameSignUp removeFromSuperview];
[passwordSignUp removeFromSuperview];
[retypepasswordSignUp removeFromSuperview];
[signUpBtn removeFromSuperview];
//[signUpBtn setBackgroundColor:[UIColor redColor]];
[self signInForm];
}
else
{
[lostPassword removeFromSuperview];
[username removeFromSuperview];
[password removeFromSuperview];
[loginBtn removeFromSuperview];
[self signUpForm];
}
}
Please suggest me some useful code as I am new in iOS.
Related
I am Having 2 Textfields stateText and providerText.If i click the first textfield means,it shows the pickerView.After That i will Select the pickerView Value.Also i have added the toolbar barbuttonitem in that pickerView.Then I have to show the pickerView value in the Textfields and hide the pickerView after selecting the value in the PickerView.Also Pointer should moves to next TextField connectionNoText after getting Values in TextFields.
1.How to hide the PickerView and show the value in TextField?
2.How to show the pickerview in the Bottom of the View irrespective of phone size?
This is my Source Code:
NewConnectionviewController.m
-(void)viewDidLoad
{
[super viewDidLoad];
//ScrollView
self.view.backgroundColor = [UIColor grayColor];
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height + 510.0)];
[self.view addSubview:scrollView];
//statePickerView
_statePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view. frame.size.height, self.view.frame.size.width, 216)];
_statePickerView.delegate = self;
_statePickerView.dataSource = self;
_statePickerView.showsSelectionIndicator = YES;
[_statePickerView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:_statePickerView];
//providerPickerView
_providerPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view. frame.size.height, self.view.frame.size.width, 216)];
_providerPickerView.delegate = self;
_providerPickerView.showsSelectionIndicator = YES;
[_providerPickerView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:_providerPickerView];
//ToolBar
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleBordered target:self action:#selector(hidePickerView:)];
toolBar.items = #[barButtonDone];
barButtonDone.tintColor=[UIColor lightTextColor];
[barButtonDone setEnabled:YES];
[_statePickerView addSubview:toolBar];
//[_providerPickerView addSubview:toolBar];
//GettingView
[self stateView];
[self providerView];
[self connectionNoView];
[self addTestView];
}
-(void)hidePickerView:(UIBarButtonItem *)sender
{
NSLog(#"clicked");
[self.selectState resignFirstResponder];
}
-(void)stateView
{
UIView *stateView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.size.width, 80)];
stateView.backgroundColor = [UIColor blueColor];
[scrollView addSubview:stateView];
//stateLabel
UILabel *stateLabel = [[UILabel alloc]initWithFrame:CGRectMake(stateView.frame.origin.x+20,35, 70, 20)];
[stateLabel setText:#"State"];
[stateLabel setTextColor:[UIColor whiteColor]];
[stateView addSubview:stateLabel];
//TextField
NSLog(#"stateViewSize==>>%f",stateView.frame.origin.y);
stateText = [[UITextField alloc]initWithFrame:CGRectMake(stateView.frame.origin.x+110, 30, 150, 40)];
stateText.textColor = [UIColor blackColor];
stateText.backgroundColor = [UIColor clearColor];
[stateText setBorderStyle:UITextBorderStyleRoundedRect];
[stateText setPlaceholder:#"select State"];
[stateText setTag:0];
[stateView addSubview:stateText];
[stateText setDelegate:self];
}
-(void)providerView
{
UIView *providerView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+80, self.view.frame.size.width, 80)];
providerView.backgroundColor = [UIColor orangeColor];
[scrollView addSubview:providerView];
NSLog(#"providerViewsize==>>%f",providerView.frame.origin.y);
//providerLabel
UILabel *providerLabel = [[UILabel alloc]initWithFrame:CGRectMake(providerView.frame.origin.x+20, 35, 70, 20)];
[providerLabel setText:#"Provider"];
[providerLabel setTextColor:[UIColor whiteColor]];
[providerView addSubview:providerLabel];
//TextField
providerText = [[UITextField alloc]initWithFrame:CGRectMake(providerView.frame.origin.x+110,30, 150, 40)];
providerText.textColor = [UIColor blackColor];
[providerText setPlaceholder:#"select Provider"];
providerText.backgroundColor = [UIColor clearColor];
[providerText setTag:1];
[providerText setBorderStyle:UITextBorderStyleRoundedRect];
[providerView addSubview:providerText];
[providerText setDelegate:self];
}
-(void)connectionNoView
{
UIView *connectionNoView = [[UIView alloc]initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height+160, self.view.frame.size.width, 150)];
connectionNoView.backgroundColor = [UIColor greenColor];
[scrollView addSubview:connectionNoView];
NSLog(#"connectionNoViewsize==>>%f",connectionNoView.frame.origin.y);
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Show UIPickerView
if (textField.tag ==0)
{
//stateText.inputView = _statePickerView;
[UIView animateWithDuration:0.5 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
_statePickerView.frame = CGRectMake(0, self.view.frame.size.height-216,self.view.frame.size.width, 216);
}
completion:^(BOOL finished){
}];
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#""
message:#"Please select state first."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;//Or return whatever as you intend
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component
{
if([thePickerView isEqual:_statePickerView])
{
return [STATE_ARRAY count];
}
else
{
return [PROVIDER_ARRAY count];
}
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if([thePickerView isEqual:_statePickerView])
{
return [STATE_ARRAY objectAtIndex:row];
}
else
{
return [PROVIDER_ARRAY objectAtIndex:row];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *firstPickerViewValue;
NSString *secondPickerViewValue;
if ([pickerView isEqual:_statePickerView])
{
firstPickerViewValue = [STATE_ARRAY objectAtIndex:row];
[_providerPickerView selectRow:row inComponent:0 animated:YES];
secondPickerViewValue = [PROVIDER_ARRAY objectAtIndex:row];
[_providerPickerView reloadAllComponents];
[stateText setText:[NSString stringWithFormat:#"%#",firstPickerViewValue]];
[providerText setText:[NSString stringWithFormat:#"%#",secondPickerViewValue]];
}
I have read through the code and to be honest Im pretty confused by your approach as I tend to avoid magic numbers when laying out the UI. Anyway I think both your questions can be solved by assigning the inputView of your slate textField and assigning the inputAccessoryView to the toolbar you created in the code.
So for example,
stateText.inputView = _statePickerView
Well that is Swift so you would have
[stateText setInputView:_statePickerView];
Then you set the Accessory View so
[stateText setInputAccessoryView: toolBar];
Although toolbar is only in scope inside your viewDidLoad method so you should fix that. This should be enough to get you back on the right path. To dismiss the pickerView just resignFirstResponder of the selected textField inside your hidePickerView method.
Note that your textfields are also confined to the methods they are created in so you should fix that too.
Finally i Found a Solution.PickerView itself a ViewController so we can't hide the pickerView.Alternative solution is,
1.Create the SubView with Height 260 and add that View to the Self.View.
(set Y Value as Self.View.Frame.Size.height).
2.Add the PickerView(default Height - 216) and ToolBar(default Height - 44) to that SubView.
3.In BarButtonItem action Move that view to the bottom.(ex.Set Frame like this) CGRectMake(0,Self.View.Frame.Size.Height,Self.View.Frame.Size.Width,216)
I have a view controller which is being added as a child view controller. The problem is that after the child controller creates its view, I am not able to modify it.
It loads everything properly, but when I want to hide a text field on clicking a button (textfield.hidden = YES), nothing happens!
This is my loadView :
-(void)loadView {
self.waitingPopup = [[WaitingPopupViewController alloc]initWithLabel:#"loading salon"];
self.view=[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
// self.view.frame=CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
scrollableTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollableTable.delegate=self;
scrollableTable.dataSource=self;
[self.view addSubview:scrollableTable];
headerHolder=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
//creating and adding backgroundImage view container and setting the image
// saloonHomeImage.backgroundColor = [UIColor grayColor];
saloonHomeImage.frame=CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height);
saloonHomeImage.contentMode = UIViewContentModeScaleAspectFill;
//[saloonHomeImage setBackgroundColor:[UIColor redColor]];
[headerHolder setBackgroundColor:[UIColor grayColor]];
[headerHolder addSubview:saloonHomeImage];
//creating and adding saloonheader label
saloonLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 32, self.view.frame.size.width, 48)];
saloonLabel.text=#"";
saloonLabel.textAlignment=NSTextAlignmentCenter;
[saloonLabel setTextColor:[UIColor whiteColor]];
[saloonLabel setFont:[UIFont fontWithName:#"vevey" size:48]];
[headerHolder addSubview:saloonLabel];
//creating and adding book appointment button
UIButton *bookAppointmentButton=[UIButton buttonWithType:UIButtonTypeSystem];
NSLog(#"%f", self.view.frame.size.height-97.5);
bookAppointmentButton.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.size.height-97.5, 216, 53);
[bookAppointmentButton setBackgroundImage:[UIImage imageNamed:#"bg-left.png"] forState:UIControlStateNormal];
[bookAppointmentButton setTitle:#"BOOK APPOINTMENT" forState:UIControlStateNormal];
[bookAppointmentButton addTarget:self action:#selector(bookAppointmentAction) forControlEvents:UIControlEventTouchUpInside];
[bookAppointmentButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[headerHolder addSubview:bookAppointmentButton];
UIButton *callButton=[UIButton buttonWithType:UIButtonTypeSystem];
callButton.frame=CGRectMake(216, self.view.frame.size.height-97.5, self.view.frame.size.width-216, 53);
[callButton setBackgroundImage:[UIImage imageNamed:#"bg-right.png"] forState:UIControlStateNormal];
[callButton addTarget:self action:#selector(callButtonAction) forControlEvents:UIControlEventTouchUpInside];
[callButton setTitle:#"CALL" forState:UIControlStateNormal];
[callButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[headerHolder addSubview:callButton];
[self getSalonDetails];
loading=[[UIImageView alloc] init];
loading.frame=CGRectMake(130,200,40,36);
[loading setBackgroundColor:[UIColor clearColor]];
loading.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"spinner-1.png"],
[UIImage imageNamed:#"spinner-2.png"],
[UIImage imageNamed:#"spinner-3.png"],
[UIImage imageNamed:#"spinner-4.png"],
[UIImage imageNamed:#"spinner-5.png"],
[UIImage imageNamed:#"spinner-6.png"],
[UIImage imageNamed:#"spinner-7.png"],
[UIImage imageNamed:#"spinner-8.png"],[UIImage imageNamed:#"spinner-9.png"],nil];
loading.animationDuration = 1.0f;
loading.animationRepeatCount = 0;
[loading startAnimating];
[self.view addSubview:loading];
loadingText = [[UILabel alloc]initWithFrame:CGRectMake(90, 240, 200, 40)];
loadingText.text = #"loading salon";
[loadingText setFont:GOTHIC_FONT(22)];
[loadingText setTextColor:[UIColor whiteColor]];
[self.view addSubview:loadingText];
articles=[Model getArticles];
}
- (void) getSalonDetails{
[[MyDataModel sharedDataModel] getSalonDetails];
}
This is the delegate method which is trying to set some fields hidden. This delegate is called when an NSURLSession call completes successfully. The control comes here as per logs but nothing gets hidden. When I add a breakpoint and inspect the fields, every object is shown as nil. If this class is used as the main view controller, I've found everything works. On making it a child view, nothing works.
-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{
[loading stopAnimating];
self.loading.hidden = YES;
self.loadingText.hidden = YES;
saloonLabel.text = #"this is texT";
if(success){
//
}
}
What I think here is that salonDetailsRecievedDelegate isn't called from the main thread, try any of the following:
1) call it in the main thread from your model as follows:
dispatch_async(dispatch_get_main_queue(), ^{
[self.delegate salonDetailsRecievedDelegate:success andStatusCode:status];
});
2) change its implementation as follows:
-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{
dispatch_async(dispatch_get_main_queue(), ^{
[loading stopAnimating];
self.loading.hidden = YES;
self.loadingText.hidden = YES;
saloonLabel.text = #"this is texT";
if(success){
//
}
});
}
I am using a UIScrollView where I got some UIButtons, to recognize that I pressed the button above, I created a subclass of UIScrollView where rewrite the method
- (BOOL) touchesShouldCancelInContentView (UIView *) view
but only enters that method when the touch is a journey, never comes when I press on the screen without more.
the UIScrollView I've created thus:
`
CGSize containerSize = CGSizeMake(320.0f, 480.0f);
CGSize containerSize2 = CGSizeMake(640.0f, 960.0f);
self.scrollView = [[UIScrollViewWithButtons alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize}];
[self.scrollView setMinimumZoomScale:0.5f];
[self.scrollView setMaximumZoomScale:1.0f];
[self.scrollView setZoomScale:0.5f];
[self.scrollView setDelegate:self];
self.scrollView.bounces = NO;
self.scrollView.bouncesZoom = NO;
self.scrollView.delaysContentTouches = NO;
self.scrollView.userInteractionEnabled = YES;
[self.scrollView setContentInset:UIEdgeInsetsZero];
[self.view addSubview:self.scrollView];
self.containerView = [[UIView alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize2}];
self.containerView.userInteractionEnabled = YES;
[self.scrollView addSubview:self.containerView];
[self.scrollView setClipsToBounds:NO];
//instanciar uimageview
fondo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 640, 960)];
[self.containerView addSubview:fondo];
[fondo setImage:[UIImage imageNamed:#"Grande.png"]];
self.scrollView.contentSize = containerSize2;
and button add
imagen = [UIButton buttonWithType:UIButtonTypeCustom];
[imagen addTarget:self action:#selector(pulsadoIzq) forControlEvents:UIControlEventTouchUpInside];
[imagen setTitle:#"" forState:UIControlStateNormal];
[imagen setFrame:CGRectMake(xUser, yUser, 50.0f, 50.0f)];
[imagen setImage:[UIImage imageNamed:#"boton.png"] forState:UIControlStateNormal];
[self.containerView addSubview:fichaUserIzq];
imagen.center = CGPointMake(xUser, yUser);`enter code here`
I need to capture the tap on the screen to the buttons
How I can do?
I would also like to know because if I have implemented this code:
img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"img.png"]];
UIPanGestureRecognizer *panRecg = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(imgDragged:)];
img.userInteractionEnabled = YES;
[img addGestureRecognizer:panRecg];
img.center = CGPointMake(160, 436);
[self.scrollView addSubview:img];
When I click on the image nothing happens, does not enter the method, only comes when I press and drag. I also want to capture when pressed over this image and so I capture only when the move.
I solved the problem, I implement this method:
-(void)singleTapGestureCaptured:(UITapGestureRecognizer*)gesture{
CGPoint touchPoint = [gesture locationInView:self.scrollView];
if ((touchPoint.x > 88)&&(touchPoint.x < 226)&&(touchPoint.y > 172)&&(touchPoint.y < 319)) {
if (rodando) {
[self pararAnimacionDado];
}
}
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];
I have a class that provides a custom menu for all its subclasses, but since i started using the text field have run to the keyboard problem so i use the normal method and embed the subclass in a resizing uiscrollview. the problem is that the scrollview doesnt cover the menu that belongs to its super class.
The idea that came to mind is to create a scrollview in the super class and inside the scrollview put the menu. I run it and everything seemed to be okay until i couldn't interact with anything on the screen other than the navigation bar and the menu which lead me to believe that maybe the subclass uielements are not subviews of the scrollview.
The problem even expands since in the subclasses I create uielements in the storyboard and in code. My question would be how to make that all uielements created in the subclass and added in self.view become subviews of the superclass' scrollview.
SUPERCLASS
- (void)viewDidLoad
{
[super viewDidLoad];
//_scrollViewMain = [[UIScrollView alloc] initWithFrame:self.view.bounds];
//[self.view addSubview:_scrollViewMain];
_slideButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(slide)];
[self.navigationItem setRightBarButtonItem:_slideButton];
_menuView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - self.navigationController.navigationBar.frame.size.height - 44, self.view.bounds.size.width, 44)];
_menuView.backgroundColor = [UIColor colorWithRed:63.0/255.0 green:63.0/255.0 blue:63.0/255.0 alpha:1.0];
[self.view addSubview:_menuView];
//[_scrollViewMain addSubview:_menuView];
UIView *redFrameView = [[UIView alloc] initWithFrame:CGRectMake(0, _menuView.frame.size.height / 2, _menuView.frame.size.width, _menuView.frame.size.height / 2)];
[redFrameView setBackgroundColor:[UIColor colorWithRed:170.0/255.0 green:0.0 blue:0.0 alpha:0.5]];
[_menuView addSubview:redFrameView];
_menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_menuButton setImage:[UIImage imageNamed:#"19-gear.png"] forState:UIControlStateNormal];
[_menuButton addTarget:self action:#selector(menu) forControlEvents:UIControlEventTouchUpInside];
_menuButton.frame = CGRectMake(16.0, 9.0, 26.0, 26.0);
_addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_addButton setImage:[UIImage imageNamed:#"13-plus.png"] forState:UIControlStateNormal];
[_addButton addTarget:self action:#selector(add) forControlEvents:UIControlEventTouchUpInside];
_addButton.frame = CGRectMake(16.0, 15.0, 14.0, 14.0);
_addButton.userInteractionEnabled = NO;
_addButton.alpha = 0.0;
_editButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_editButton setImage:[UIImage imageNamed:#"187-pencil.png"] forState:UIControlStateNormal];
[_editButton addTarget:self action:#selector(edit) forControlEvents:UIControlEventTouchUpInside];
_editButton.frame = CGRectMake(16.0, 15.0, 14.0, 14.0);
_editButton.userInteractionEnabled = NO;
_editButton.alpha = 0.0;
_deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteButton setImage:[UIImage imageNamed:#"11-x.png"] forState:UIControlStateNormal];
[_deleteButton addTarget:self action:#selector(delete) forControlEvents:UIControlEventTouchUpInside];
_deleteButton.frame = CGRectMake(16.0, 15.0, 14.0, 14.0);
_deleteButton.userInteractionEnabled = NO;
_deleteButton.alpha = 0.0;
_downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_downloadButton setImage:[UIImage imageNamed:#"57-download.png"] forState:UIControlStateNormal];
[_downloadButton addTarget:self action:#selector(download) forControlEvents:UIControlEventTouchUpInside];
_downloadButton.frame = CGRectMake(16.0, 15.0, 11.0, 14.0);
_downloadButton.userInteractionEnabled = NO;
_downloadButton.alpha = 0.0;
_uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_uploadButton setImage:[UIImage imageNamed:#"56-cloud.png"] forState:UIControlStateNormal];
[_uploadButton addTarget:self action:#selector(upload) forControlEvents:UIControlEventTouchUpInside];
_uploadButton.frame = CGRectMake(16.0, 15.0, 21.0, 14.0);
_uploadButton.userInteractionEnabled = NO;
_uploadButton.alpha = 0.0;
_shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_shareButton setImage:[UIImage imageNamed:#"124-bullhorn.png"] forState:UIControlStateNormal];
[_shareButton addTarget:self action:#selector(share) forControlEvents:UIControlEventTouchUpInside];
_shareButton.frame = CGRectMake(16.0, 15.0, 21.0, 14.0);
_shareButton.userInteractionEnabled = NO;
_shareButton.alpha = 0.0;
[_menuView addSubview:_addButton];
[_menuView addSubview:_editButton];
[_menuView addSubview:_deleteButton];
[_menuView addSubview:_downloadButton];
[_menuView addSubview:_uploadButton];
[_menuView addSubview:_shareButton];
[_menuView addSubview:_menuButton];
_isMenuVisible = NO;
}
FIRST attempt but the scrolldidn't included the menuview in the superclass
- (void)viewDidLoad
{
[super viewDidLoad];
[self registerForKeyboardNotifications];
self.title = [_exercise valueForKey:kExerciseName];
[super ableAdd];
[super ableDownload];
[super ableShare];
if ([[_exercise valueForKey:kExerciseIsDefault] boolValue]) {
[super ableUpload];
[super ableDelete];
}
_doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done)];
_nameLabel.text = [_exercise valueForKey:kExerciseName];
_nameLabel.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
_categoryLabel.text = [[_exercise valueForKey:kExerciseEType] valueForKey:kExerciseTypeName];
_categoryLabel.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
_gearLabel.text = [[_exercise valueForKey:kGear] valueForKey:kGearName];
_gearLabel.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
_addRecordButton = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 30) / 2, 7, 30, 30)];
[_addRecordButton setImage:[UIImage imageNamed:#"85-trophy.png"] forState:UIControlStateNormal];
[_addRecordButton addTarget:self action:#selector(addRecord) forControlEvents:UIControlEventTouchUpInside];
[_toolView addSubview:_addRecordButton];
_showChartButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 50, 7, 30, 30)];
[_showChartButton setImage:[UIImage imageNamed:#"16-line-chart.png.png"] forState:UIControlStateNormal];
[_showChartButton addTarget:self action:#selector(showChart) forControlEvents:UIControlEventTouchUpInside];
[_toolView addSubview:_showChartButton];
_numberOfPages = 3;
_currentPage = 1;
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 174, 320, self.view.bounds.size.height - 262)];
_scrollView.pagingEnabled = YES;
_scrollView.contentSize = CGSizeMake(_scrollView.bounds.size.width * _numberOfPages, _scrollView.bounds.size.height);
_scrollView.delegate = self;
_scrollView.showsHorizontalScrollIndicator = NO;
_textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height)];
_textView.contentSize = CGSizeMake(_scrollView.bounds.size.width, _scrollView.bounds.size.height);
_textView.text = [_exercise valueForKey:kExerciseOverview];
_textView.editable = NO;
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(_scrollView.bounds.size.width * 1, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height)];
_tableView.contentSize = CGSizeMake(_scrollView.bounds.size.width, _scrollView.bounds.size.height);
_tableView.dataSource = self;
_tableView.delegate = self;
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:#selector(handleLongPress:)];
longPress.minimumPressDuration = 2.0;
longPress.delegate = (id<UIGestureRecognizerDelegate>)self;
[_tableView addGestureRecognizer:longPress];
_movieView = [[UIWebView alloc] initWithFrame:CGRectMake(_scrollView.bounds.size.width * 2, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height)];
_movieView.opaque = YES;
_movieView.backgroundColor = [UIColor whiteColor];
_movieView.autoresizesSubviews = YES;
[_movieView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[_exercise valueForKey:kExerciseUrlAddress]]]];
[_scrollView addSubview:_textView];
[_scrollView addSubview:_tableView];
[_scrollView addSubview:_movieView];
[_scrollView scrollRectToVisible:CGRectMake(_scrollView.bounds.size.width * 1, 0, _scrollView.bounds.size.width, _scrollView.bounds.size.height) animated:NO];
[_scrollViewMain addSubview:_scrollView];
//[self.view addSubview:_scrollView];
_pageControl.numberOfPages = _numberOfPages;
_pageControl.currentPage = _currentPage;
_records = [[NSMutableArray alloc] init];
_records = [[NSArray arrayWithArray:[[_exercise valueForKey:kExerciseERecords] allObjects]] mutableCopy];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:kExerciseRecordRecordDate ascending:NO];
[_records sortUsingDescriptors:[NSArray arrayWithObject:sort]];
}
- (void)viewDidDisappear:(BOOL)animated
{
if (self.editing) {
[super setPan];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[_tableView setEditing:editing animated:animated];
[super setPan];
if (self.navigationItem.rightBarButtonItem == nil) {
self.navigationItem.rightBarButtonItem = _doneButton;
}
_addRecordButton.enabled = !editing;
_showChartButton.enabled = !editing;
if (![[_exercise valueForKey:kExerciseIsDefault] boolValue]) {
[super ableUpload];
[super ableDelete];
_textView.editable = editing;
}
}
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
_scrollViewMain.contentInset = contentInsets;
_scrollViewMain.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, _activeField.frame.origin) ) {
CGPoint scrollPoint = CGPointMake(0.0, _activeField.frame.origin.y-kbSize.height);
[_scrollViewMain setContentOffset:scrollPoint animated:YES];
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_scrollViewMain.contentInset = contentInsets;
_scrollViewMain.scrollIndicatorInsets = contentInsets;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
_activeField = textField;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
_activeField = nil;
}
How can I add the Page control for UIScrollView with UIImageView in iOS. If I selected certain page control bullets means I want to move the selected image. If I move image means my pagecontrol bullets also want to move in UIScrollView .
- (void)viewDidLoad
{
NSLog(#"Welcome to Home Page");
[super viewDidLoad];
// self.view.backgroundColor=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:#"bg-image.png"]];
UIImage * img = [UIImage imageNamed:#"bg-image.png"];
[scrollView setBackgroundColor:[UIColor colorWithPatternImage:img]];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.contentSize=CGSizeMake(1400, 100);
UIImageView *tempImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti01.png"]];
tempImageView2.frame=CGRectMake(10, 60, 200, 200);
[scrollView addSubview:tempImageView2];
UIImageView *tempImageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti02.png"]];
tempImageView3.frame=CGRectMake(240, 60, 200, 200);
[scrollView addSubview:tempImageView3];
UIImageView *tempImageView4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti03.png"]];
tempImageView4.frame=CGRectMake(470, 60, 200, 200);
[scrollView addSubview:tempImageView4];
UIImageView *tempImageView5 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti04.png"]];
tempImageView5.frame=CGRectMake(700, 60, 200, 200);
[scrollView addSubview:tempImageView5];
UIImageView *tempImageView6 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti05.png"]];
tempImageView6.frame=CGRectMake(930, 60, 200, 200);
[scrollView addSubview:tempImageView6];
UIImageView *tempImageView7 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"sti06.png"]];
tempImageView7.frame=CGRectMake(1160, 60, 200, 200);
[scrollView addSubview:tempImageView7];
self.view=scrollView;
[scrollView addSubview:tempImageView2];
[scrollView addSubview:tempImageView3];
[scrollView addSubview:tempImageView4];
[scrollView addSubview:tempImageView5];
[scrollView addSubview:tempImageView6];
[scrollView addSubview:tempImageView7];
scrollView.userInteractionEnabled = YES;
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(22, 100, 1800, 500);
// [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(buttonTest:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:btn];
}
- (IBAction)buttonTest:(id)sender {
MSDescriptionpage *aSecondPageController = [[MSDescriptionpage alloc] initWithNibName:#"MSDescriptionpage" bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
[aSecondPageController release];
}
I had to do the same , what I did is I used two view controller (page view controller for page swipe ) and main view controller with UIImage views and you can add scroll view with images in this ..
these in page VC
inside did load
[pageController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionReverse
animated:NO
completion:nil];
[self addChildViewController:pageController];
[[self view] addSubview:[pageController view]];
for (UIGestureRecognizer *gR in pageController.gestureRecognizers) {
gR.delegate = self;
}
[pageController didMoveToParentViewController:self];}
These to call another vc
- (UIViewController *)pageViewController:
(UIPageViewController *)pageViewController viewControllerBeforeViewController:
(UIViewController *)viewController
{
for (UIGestureRecognizer *recognizer in pageController.gestureRecognizers) {
if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) {
recognizer.enabled = NO;
}
}
NSUInteger index = [self indexOfViewController:
(MainViewController *)viewController];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}