The use of some statements in iOS development

Source: Internet
Author: User

Use of 1.UISegmentedControl

Split controller is the basic use of several switches connected together

Uisegmentedcontrol *SEGMENTEDVC = [[Uisegmentedcontrol alloc] initwithitems:@[@ "spatial dynamics", @ "JIII", @ "DDA"];

Sets the background color it selects

Segmentedvc.tintcolor = [Uicolor Graycolor];

Which one is selected by default

Segmentedvc.selectedsegmentindex = 0;

Segmentedvc.frame = CGRectMake (0, 0, 320, 35);

Self.navigationItem.titleView = SEGMENTEDVC;

SELF.SEGMENTEDVC = SEGMENTEDVC;

2.switch Precautions for use

Switch (ButtonType) {

Case://Mood 0

{

If you want to define a variable in switch, be sure to add braces, let it clear the scope, from that place to where

To write multiple lines of code, you must add a brace here, because the scope of the problem

Break

}

3. Add a left and right drag effect to a view code

Add a drag gesture to Contentview

    • (void) test1{

Uipangesturerecognizer *pan = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (pan:)];

[Contenview Addgesturerecognizer:pan];

}

/**

* But this method is called when the Contentview is dragged

*/

-(void) pan: (Uipangesturerecognizer *) pan

{

Remove View drag move distance

Cgpoint point = [Pan TranslationInView:pan.view];

if (pan.state = = Uigesturerecognizerstateended | | pan.state = = uigesturerecognizerstatecancelled) {//When dragging ends or drags is interrupted, view restores The original position

Revert to the original location

Self.contenView.transform = cgaffinetransformidentity;

} else {

Point.x * 0.2 produces a good drag effect, with a good user experience

Self.contenView.transform = cgaffinetransformmaketranslation (point.x * 0.2, 0);

}

}

The use of some statements in iOS development

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.