Home  >  Blog  >   iPhone  > 

Creating Views (Switch, Web & Scroll) in iPhone

SwiftUI is built around the concept of composition, which implies that we may create a variety of smaller views and then combine them into a larger one. As a result, we may save time by reusing views on a much larger scale. Learn how to build iPhone screens with switch, web, and scroll views.

Rating: 4
  
 
2132

Switching VIEWS:

. h file:
[1. Using Present model view Controller]

# import
# import   “SecondviewController. h”
@ interface Switching view Controller: UIViewController
{
}
-(IBAction) next clicked;
 @ end

.m file:

# import “Switching viewController .h”
@ implementation Switchingview Controller
-( IBAction)  nextClicked
{
SecondviewController    * second = [[ SecondviewController alloc]
InitwithNibName:  @  “SecondViewController” bundle :nil];
[ self PresentModelviewController : Second animated: YES];
}

Second view controller. M:

-(IBAction) backClicked
{
[ self dismissModel  viewControllerAnimated : YES];
}

Second viewController:

# import
@ interface Second view Controller : UIviewController
{
}
-(IBAction) backclicked;
@ end
Inclined to build a profession as IOS Developer? Then here is the blog post on IOS Development Certification Training.

[ 2: by using adding subviews ]

[  self view add subview.v1];
[ self view removesubview:v1];

Web View:

-(void) viewDidLoad
{
UIWebView  *webView=  [[UIWebView  alloc]
InitWithFrame  : CGRectMake  (0,44,320,436)];
NSURL       *url   =   [ NSURL URLWithString  :@
                                     .http :// www.google.com”];
NSURLRequest     * request  =   [NSURL Request
                                                           RequestWithURL: url];
[web view loadRequest: request];
Webview: delegate  =  Self;
[  self. View  addSub view:  web view];
[ web view release];

Loading Previous:

If  (web view canGoBack)
   [webview  goBack];

loading forward action:

If ( web view . canGoForward)
   [ web view go forward];

is web view in loading:

If (webview. Loading)
{
// in loading.
}
[ super viewDidLoad];
}

# Program Mark UI Web View Delegate Methods:

-(void)  webviewDidStartLoad  :  (UIwebview   *)  webview
{
NSLog (@   “ webviewDidstartLoad called”);
}
-(void) webviewDidFinishload:  (UIwebview   *) webview
{
NSLog (@  “  webviewFinishload   called”);
}
-(void) webview  :  (UIwebview     *)   webview.
DidfailloadwithError: (NSError     *)  error
{
NSLog (@   “did fail load  with error called”);
}
MindMajix Youtube Channel

Scroll view:

Scroll views are created as any other view is, either programmatically or in Interface Builder. Only a small amount of additional configuration is required to achieve basic scrolling capabilities.
1. Scroll for image
2. Scroll for views

Related Article: iPhone Interview Questions & Answers

1. Scroll for images:

. h file:

# import  
@ interface  ScrollView Viewcontroller  :   UIViewController
{
IBoutlet     UIScrollview        *Scroll;
IBoutlet      UIImageview    * imageView;
}
@ end

.m file:

-(void) viewDidLoad
{
UIImage     *img  =  [ UIImage Named.
                     @  “photo  on 2011-07-03 at 10.28.jpg”];
CGSize Size =  img.  Size;
Img view. Frame  =  CGRectMake  (0,0 size. Width,  size. Height);
Img  view. Image    =   img;
[ Scroll    addSubview: imgview];
[ scroll setContentSize: img. Size];
}

Xib file:

Dynamically Adding img view to Scroll View:

-(void) viewDidLoad
{
UIScrollview       *Scroll  =  [[ UIScroll view alloc ]
InitWithFrame  :  [  UIScreenmainScreen]. application Frame];
UI image   *img  =  [UI image image named:@ “1.jpg”];
CG size   size  =  img .size;
UI image view   * img view  =[[UI image  view  alloc]
Init with frame : CG rect make (0,0 size width , size height)];
Img view image   = img;
[  Scroll addSub view: img view];

Setting Content Size

Scroll. ContentSize   =   imgview. frame. Size;
[  Self . view  addSub view :Scroll];
[  img view        release];
[  Scroll             release];
[ Super              view did load];
}              
2. Scroll for view:-

.h file:

# import
@ interface  Scrollview viewController: UIviewController
{
IBoutlet   UIScroll view  * Scroll;
IBoutlet    UIView     *     Signupview;
}

.m file:

-(void) viewDidLoad
{
[scroll    addSubview: Signupview];
Scroll. Contentsize   =   Signupview .frame .Size;
}

.xib file:

Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
IOS Development TrainingMar 25 to Apr 09
IOS Development TrainingMar 28 to Apr 12
IOS Development TrainingApr 01 to Apr 16
IOS Development TrainingApr 04 to Apr 19
Last updated: 22 March 2023
About Author
Remy Sharp
Ravindra Savaram

Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.

Recommended Courses

1 /15