Xamarin.ios UIKit Controls

XAMARIN.IOS UIKIT CONTROLS

XAMARIN.IOS UIKIT CONTROLS

UIKit

The UIKit framework provides the required infrastructure for your iOS or tvOS apps. It provides the window and view architecture for implementing your interface, the event handling infrastructure for delivering Multitouch and other types of input to your app, and the main run loop needed to manage interactions among the user, the system, and your app. Other features offered by the framework include animation support, document support, drawing and printing support, information about the current device, text management and display, search support, accessibility support, app extension support, and resource management.

Important

Use UIKit classes only from your app’s main thread or main dispatch queue, unless otherwise indicated. This restriction particularly applies to classes derived from UIResponder or that involve manipulating your app’s user interface in any way.

What are the main UI Controllers
1) UILabel
2) UIButton
3) UITextField
4) UITextView
5) UIDatePiker
6) UITimePicker
7) UIImageView
8) UIWebView
9) UISwitch
10) UISlider

UILabel
A view that displays one or more lines of read-only text, often used in conjunction with controls to describe their intended purpose. More details available on apple site.

Now time to add label and set text on xamarin.ios
Create new project on visual studio
File > New Solution > you will see new window to select template

On left side select ios app and from right side select single view app as a template.
xamarin.ios uikit new solution

You can check my previous post Xamarin.ios on Visual studio (beginners) to get basic idea about Xamarin.ios.

Now you know how to add a label and display text.

How to Add Button
Now Lets see how to add Button to the View and add action for the button. As you did above post , add UiButton to the view.
In the Toolbox Pad, type “UIButton” into the search bar and drag a button onto the design surface (the area in the center)

select button and see the property window. Under property you need to select Events tab. You can see all the events under button.

UIButton Events

UIButton Events

Click on the text box under Up Inside and type method name for selected Button. My method name is “tapOnButton”. After enter the name click Enter. The cursor will move to the View Controller and asking the place to method. You can use up and down keys to move to the positions. Once you select position enter. it will add following method.

1
2
3
4
 partial void tapOnButton(UIButton sender)
 {
      lable.Text = "Text Changed";
 }

Run the application and click on the button on simulator application.

How to Add UITextField
Search TextField and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “textFieldTxt”. That’s call IBOutlet.

IBOutlet
An outlet is a property of an object that references another object. The reference is archived through Interface Builder. The connections between the containing object and its outlets are reestablished every time the containing object is unarchived from its nib file. The containing object holds an outlet declared as a property with the type qualifier of IBOutlet and a weak option.

Now we can change the code to update label with entered text.

1
2
3
4
partial void tapOnButton(UIButton sender)
{
    lable.Text = textFieldTxt.Text;
}

How to Add UITextView
Search TextView and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “textViewTxt”. UITextView are also editable, but provide vertical scrolling when the text is too long to display all at one.

How to Add UIDatePiker
Search UIDatePicker and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “datePicker”.
You can use a date picker to allow a user to enter either a point in time (calendar date, time value or both) or a time interval (for example for a timer). The date picker reports interactions to its associated target object.
You can see more details from apple web site

How to Show Image
Search UIImageView and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “imgView”.
under property you can see as image and set image name for it. When you run it you can see the image on View.

How to Add Web View
Search UIWebView and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “webView”. To set the web url use following code lines. Please add that line on ViewDidLoad method.

1
webView.LoadRequest(new NSUrlRequest(new NSUrl("https://www.yahoo.com")));

How to Add UISlider
Search UISlider and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “slider”. To change slider value use following code line.

1
slider.Value = 0.9f;

strong>How to Add UIProgressBar
Search UIProgressBar and Drag and drop to the View. Go to the property Window (You need to select widget on the tab). Enter the name as “progressBar”. To change slider value use following code line.

1
prgressBar.Progress = 0.9f;

Stay tune for the Next

Slide
presentation At tiqri

Refer :https://developer.apple.com/documentation/uikit

Write a Reply or Comment

Your email address will not be published.