iOS Development--uiscrollview Add xib Custom View

Source: Internet
Author: User

Implementation features: 3-Step registration process, click Next to enter the next page, fill in the information.

Implementation ideas:

1. Because you need to add the "Quit Registration" button on the first registration page, the Uinavigation implementation is not used. Instead, use a uicontroller.

2. Three registration pages are of different lengths, so add Uiscrollview as Subview to the view of the VC (Uiscrollview frame Length-width write).

3. Customize three UIView, change Uiscrollview's contentviewsize according to frame of view when need to show a view

Specifically related to:

1. Use Xib to customize the UIView subclass (not associated with a VC)

Frame refers to the position and size of the view in the parent view coordinate system. (The reference point is the father's coordinate system)

Bounds refers to:

Frame of 2.UIScrollView:

Three basic properties of UIView

Frame: Is the CGRect type, and the view's position and size in the parent view coordinate system changes the center of the frame. (The reference point is the father's coordinate system)

Center: Is the Cgpoint type, which refers to the center point of the entire view, changing the view's center will also change the frame. (relative to Parent view)

Bounds: Is the cgrect type, the position and size of the view in its own coordinate system. (The reference point is its own coordinate system)

Properties of the Uiscrollview

Contentsize: The size that scrolling attempts to show can also be understood as a scrolling area.

Scrollview.frame = (0,0,320,480); scrollview.contentsize = (320,480*2);//can scroll up and down scrollview.contentsize = (320*2,480); /can scroll left or right

So I first in the VC xib to determine the Uiscrollview frame.

And Uiscrollview's contentsize needs to be based on the view changes it shows.

Because the view is defined in Xib and is addsubview to Srollview, this sub-view does not have the appropriate frame--associated with the view on the VC, as the view of the usual VC. At this point, the "standalone" view we define will vary based on size in simulated metrics-because it is added to a uiscrollview, it does not determine its size based on the frame.size.wildth of ScrollView. Instead, ScrollView determines his contentview based on what is displayed, which is the view.

So before adding Subview to ScrollView, manually define the Subview frame so that its size is not defined by Xib.

Register2 Here for Custom view

#import "Register2.h" #import "Utils.h" @implementation register2/*//only override drawrect:if you perform custom drawing .//An empty implementation adversely affects performance during animation. */-(void) DrawRect: (cgrect) rect {   self.frame =cgrectmake (0, 0, main_width, n);   Self.nextBtn.layer.cornerRadius = 8;   Self.nextBtn.layer.masksToBounds = YES;  }

Set the contentsize of the scrollview so that it can only scroll up and down, and the scrolling range is exactly the size of the child view.

[Self.scrollview Setcontentsize:cgsizemake (Self.secondView.frame.size.width, self.secondview.frame.size.height+ 200)];

This way, even if the size in the simulated metrics of the child view is iphone 5s, the effect on the iphone6p is still correct.

iOS Development--uiscrollview Add xib Custom View

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.