Common UI controls and ui controls

Source: Internet
Author: User

Common UI controls and ui controls

// Create a warning box object

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "warning! "Message: @" are you sure you want to exit? "Delegate: self cancelButtonTitle: @" cancel "otherButtonTitles: @" OK ", @" continue ", @" View ", nil];

// Display the warning box

[AlertView show];

 

// Comply with the UIAlertViewDelegate protocol in. h and implement the method in the Protocol

-(Void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex

{

// The buttonIndex parameter can be used to identify the button to be clicked.

NSLog (@ "% I", buttonIndex );

}

(2)

// Create an ActionSheet object

UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "delete image" otherButtonTitle: nil, nil];

// Add to self. view

[ActionSheet showInView: self. view];

// You also need to observe the methods in the. h file in the UIActionSheetDelegate protocol implementation protocol

-(Void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex

{

NSLog (@ "% I", buttonIndex );

}

(3)

// Create a step object

UIStepper * stp = [[UIStepper alloc] initWithFrame: CGRectMake (100,100,100, 0)

[Self. view addSubview: stp];

// Set the maximum and minimum values of the stepper.

Stp. maximumValue = 10;

Stp. minimumValue = 0;

// Set the default step range to one

Stp. stepValue = 2;

[Stp addTarget: self action: @ selector (stpClick :) forControlEvents: UIControlEventValueChanged];

// Create a progress bar object

// The maximum and minimum values cannot be set for the progress.

// The value range of the progress bar is 0 ~ 1

UIProgressView * p = [[UIProgressView alloc] initWithFrame: CGRectMake (10,150,300, 10)];

P. tag= 200;

[Self. view addSubview: p];

// P. progress sets the progress bar

 

(4)

NSArray * arr = @ [@ "menu", @ "Shopping Cart", @ "checkout", @ "unit price"];

UISegmentedCotrol * seg = [[UISegmentControl alloc] initWithItems: arr];

[Self. view addSubview: seg];

Seg. frame = CGRectMake (100,100,200, 30 );

// Set the default position

Seg. selectedSegmentIndex = 1;

// Add a button to the segment Control

[Seg insertSegmentWithTitle: @ "quantity" atIndex = 1 animated: YES];

// Add an event to the segment Control

[Seg addTarget: self action: @ selector (segChange :) forControlEvents: UIControlEventValueChanged];

-(Void) segChange :( UISegmentedControl *) sg

{

NSLog (@ "% I", sg. selectedSegmentIndex );;

}

(5)

UISlider * slider = [[UISlider alloc] initWithFrame: CGRectMake (10,200,300, 30)];

[Self. view addSubview: slider];

// Sets the maximum value of a row.

Slider. maximumValue = 50;

// Set the minimum value of a row

Slider. minimunValue = 0;

// Add a slide event to the stroke

[Slider addTarget: self action: @ selector (sliderChange :) forControlEvents: UIControlEventValueChanged];

// Call the method after sliding ends

Slider. continuous = NO;

// Set the slider color on both sides

Slider. minimumTrackTintColor = [UIColor redColor];

Slider. maxmumTrackTintColor = [UIColor blueColor];

// Set the slide between left and right images

Slider. maximumValueImage = [UIImage imageNamed: @ "B .png"];

Slider. minimumValueImage = [UIImage imageNamed: @ "a.png"];

-(Void) sliderChange :( UISlider *) s

{

NSLog (@ "% f", s. value );

}

 

(6)

// Create a switch control object

UISwitch * sw = [[UISwitch alloc] initWithFrame: CGRectMake (100,100, 0 );

[Self. view addSubview: sw];

// Set whether the switch is on.

[Sw setOn: YES];

[Sw addTarget: self action: @ selector (swChange :) forControlEvents: UIControlEventValueChanged];

 

// Create a UIActivityIndicatorView object for network loading

UIActivityIndicatorView * act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite];

Act. frame = CGRectMake (100,150,100,100 );

[Self. view addSubview: act];

Act. tag = 100;

// Start loading

[Act startAnimating];

 

 

-(Void) swChange :( UISwitch *) sw

{

UIActivityIndicatorView * act = (UIActivityIndicatorView *) [self. view viewWithTag: 100];

If (sw. isOn ){

[Act startAnimating];

NSLog (@ "on ");

}

Else

{

// Stop loading

[Act stopAnimating];

NSLog (@ "off ");

}

}

(7)

// Create a webpage to load the control object

UIWebView * webView = [[UIWebView alloc] initWithFrame: CGRectMake (20,90, 220,220)];

WebView. backgroundColor = [UIColor redColor];

[Self. view addSubview: webView];

WebView. tag = 200;

 

 

-(Void) btnClick :( UIButton *) bt

{
// Obtain the text box object

UITextField * textField = (UITextField *) [self. view viewWithTag: 100];

// Obtain the URL in the text box

NSString * strURL = textField. text;

// Obtain the webView object

UIWebView * webView = (UIWebView *) [self. view viewWithTag: 200];

NSURL * url = [NSURL URLWithString: strURL];

// Encapsulate the network request class

NSURLRequest * request = [[NSURLRequest alloc] initWithURL: url];

// Load network requests

[WebView loadRequest: request];

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.