After we finish helloword, we will learn some of the simplest and most practical controls. 1. Implementation of uialertview:
The effect is as follows:
2. the difference between uiactionsheet and uialertview is that they are used to prompt the user for operations, while uiactionsheet is displayed from the bottom. When a user has dangerous operations, it is used to prompt whether the user can use uiactionsheet to indicate whether or not to delete a file. confirm deletion
First. the hfile must implement uiactionsheetdelegate and implement the method in delegate: actionsheet: diddismisswithbuttonindex. When you click the button, the text will become blank when you click the cancel button in the above Code; effect
3. Two wait controls: uiactionindicatorview and uiprogressview. Let's create a applet to meet their functional requirements: Click the progress bar to start and go forward. The installation dialog box is displayed. Click Install uiactionindicatorview to start rotating the interface as follows:
. H code @ interface seek: uiviewcontroller <uiactionsheetdelegate> {uiactivityindicatorview * seekbar; uiprogressview * probar; nstimer * time;} @ property (nonatomic, retain) iboutlet limit * seekbar; @ property (nonatomic, retain) iboutlet uiprogressview * probar; @ property (nonatomic, retain) nstimer * time;-(ibaction) downlond :( ID) sender; @ end. M code-(ibaction) downlond :( ID) sender {probar. progress = 0.0; time = [nstimer scheduledtimerwithtimeinterval: 1.0 target: Self selector: @ selector (updateinstall)
Userinfo: Nil repeats: Yes];}-(void) updateinstall {probar. progress = probar. progress + 0.1; If (probar. progress = 1.0) {[time invalidate]; uiactionsheet * actionsheet = [[uiactionsheet alloc] initwithtitle: @ "Install" delegate: Self
Cancelbuttontitle: @ "cancel" destructivebuttontitle: @ "Install" otherbuttontitles: nil, nil]; [actionsheet showinview: Self. view]; [actionsheet release] ;}}-(void) actionsheet :( uiactionsheet *) actionsheet diddismisswithbuttonindex :( nsinteger) buttonindex {If (buttonindex = [actionsheet destructivebuttonindex]) {If ([seekbar isanimating]) {[seekbar stopanimating];} else {[seekbar startanimating] ;}} nstimer can start a thread implicitly, scheduledtimerwithtimeinterval specifies the time for the thread to sleep and call it once. The updateinstall method specified by selector runs as follows:
This time, let's do more controls. First, let's look at these controls on the screen.
There are three uibutton implementation functions above: clicking the top button has a highlighted effect can control whether the following two buttons can be clicked to implement the uiswitch and uisilder functions: the uisilder is dragged to the head switch to the on status. Other switches are off, and the uisegmentedcortrol control is below to implement the functions: click "0" in the first console and click "off". Then, the uitoorbar is added: click "uisilder" in the first entry to change to "Max". Click "uisilder" in the last entry to change to "min. the hfile method is ordered according to the above functional order @ interface mostcontrolviewcontroller: uiviewcontroller {uibutton * btn1; uibutton * btn2; uislider * probar; uiswitch * onoroff;} @ property (nonatomic, retain) iboutlet uibutton * btn1; @ property (nonatomic, retain) iboutlet uibutton * btn2; @ property (nonatomic, retain) iboutlet uislider * probar; @ property (nonatomic, retain) iboutlet uiswitch * onoroff;-(ibaction) hightlight :( ID) sender;-(ibaction) drawing :( ID) sender;-(ibaction) segmentedcontrol :( ID) sender;-(ibaction) on :( ID) sender;-(ibaction) off :( ID) sender; @ end. M file-(ibaction) hightlight :( ID) sender {If (btn1.enabled = Yes) {btn1.enabled = no; btn2.enabled = no; [(uibutton *) sender) settitle: @ "nohight" forstate: uicontrolstatenormal];} else {btn1.enabled = yes; btn2.enabled = yes; [(uibutton *) sender) settitle: @ "hight" forstate: uicontrolstatenormal] ;}}-(ibaction) drawing :( ID) sender {If ([(uislider *) sender value] ==( (uislider *) sender ). maximumvalue) {[onoroff Seton: Yes animated: Yes];} else {[onoroff Seton: No animated: Yes] ;}}-(ibaction) segmentedcontrol :( ID) sender {uisegmentedcontrol * segment = (uisegmentedcontrol *) sender; If (segment. selectedsegmentindex = 0) {nslog (@ "0");} else if (segment. selectedsegmentindex = 2) {[onoroff Seton: No animated: No] ;}}-(ibaction) on :( ID) sender {[probar setvalue: probar. maximumvalue];}-(ibaction) off :( ID) sender {[probar setvalue: probar. minimumvalue];} the code looks simple. Note the following points:
Shows touch on highlight is easy to hook up.
Webview ControlThis implementation is also a relatively simple webview control implementation effect. The above input box and a button show the webview display effect.
Because it is relatively simple, you can simply look at the code without too much explanation. h文: @ interface Syntax: uiviewcontroller <strong> {uitextfield * uiltext; uiwebview * urlview;} @ property (nonatomic, retain) iboutlet uitextfield * uiltext; @ property (nonatomic, retain) iboutlet uiwebview * urlview;-(ibaction) loadurl :( ID) sender; @ end. M file:-(void) viewdidload {urlview. delegate = self;}-(ibaction) loadurl :( ID) sender {[uiltext resignfirstresponder]; nsurl * url = [nsurl urlwithstring: uiltext. text]; nsurlrequest * request = [nsurlrequest requestwithurl: url]; [urlview loadrequest: request];}-(void) webviewdidfinishload :( uiwebview *) webview {} uiwebviewdelegate needs to be implemented by webviewdidfinishload: You can enter the code after loading.