iOS Basics-Launchscreen, APPIcon, StatusBar, Uiscrollview, uipagecontrol through case studies
The case to be fulfilled today
First, Launchscreen
1, set the program Launchscreen
Configure the startup page in the project configuration file and layout in Launchscreen.storyboard
2. Set Launchscreen time
//单位:秒[NSThread sleepForTimeInterval:1.5f];
Second, APPIcon
1, naming rules: iOS app icons are named rules, corresponding to different devices have different sizes
The rules are: name + size + (@nx), such as
- 29x29 size is 29x29.
- [Email protected] size is 58x58
- [Email protected] size is 87x87
2, set Appcicon: Drag these pictures to the default assets folder in AppIcon, will automatically generate corresponding icon adaptation version
Third, StatusBar
1, global settings, for all pages to take effect
① settings in the configuration file
② Code Settings
//设置是否隐藏状态栏[UIApplication sharedApplication].statusBarHiddenYES;//设置状态栏颜色,默认是黑色,这里修改为白色[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
2, local settings, for a page to take effect
//设置是否隐藏状态栏- (BOOL)prefersStatusBarHidden{ returntrue;}//设置状态栏颜色,默认是黑色,这里修改为白色- (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent;}
Iv. userinteraction (additional content)
Userinteraction refers to the user interaction, that is, whether to allow the user to do any action on the view, each view has this property, the default is Yes
① settings in the configuration file
Set in ② code
[view setUserInteractionEnable:NO];
v. Subviews (additional content)
Subviews refers to all the child view in a view
1, remove all subviews
[_fatherView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
2. Traverse All Subviews
//遍历所有subviews[_fatherView.subviewsUIView* _Nonnull obj,NSUInteger idx,BOOL * _Nonnull stop{ //obj 表示数组中的对象 //idx 表示下标 //*stop YES 表示跳出遍历}];
vi. Uiscrollview and Uipagecontrol
1. Build Uiscrollview Interface
You can see Uiscrollview nested 1 Carousel graphs and several uiimageview, and the carousel diagram is comprised of Uiscrollview and Uipagecontrol (indicators), It is important to note that both the head view and the bottom view must be in the same class as the Uiscrollview, and after Uiscrollview is added, this can be overridden on Uiscrollview
2. Attribute declaration
//uiscrollviewdelegate Declaration Delegate @interface viewcontroller () <uiscrollviewdelegate>//Carousel diagram@property(Weak,nonatomic)Iboutlet Uiscrollview*bannerview;//main interface@property(Weak,nonatomic)Iboutlet Uiscrollview*mainscrollview;///Last picture to set the Y value of the Uiscrollview@property(Weak,nonatomic)Iboutlet Uiimageview*lastimageview;//Indicator@property(Weak,nonatomic)IboutletUipagecontrol *bannerindication;//Timer@property(nonatomic,Strong) Nstimer *timer;@end
3. Main interface Code structure
Delegates in iOS are similar to listening events in Android, and the steps are similar to Android-like implementations
#pragma Main method- (void) Viewdidload {[SuperViewdidload];//Set the Start interface time[NsthreadSleepfortimeinterval:1.5F];//Set master Page UI[ SelfSETUPUI];}#pragma custom Methods#pragma setting up the UI- (void) setupui{//Set scroll delegates_bannerview. Delegate= Self; [ SelfSetupmainscrollview]; [ SelfSetupbannerview]; [ SelfSetupbannerindication]; [ SelfInittimer];//Set the priority of the timer[ SelfSetuppriority];}
4. Implementation code
#pragma custom Methods#pragma setting the main interface-(void) setupmainscrollerview{//Set Scollerview slide x and y range, Parameter 1: Indicates that the x-axis cannot slide parameter 2: Represents the y-coordinate of the y-axis sliding to the last view_mainscrollerview. Contentsize= Cgsizemake (0, Cgrectgetmaxy (_lastimageview. Frame));//Hide scroll bar_mainscrollerview. Showsverticalscrollindicator=NO; _mainscrollerview. Showshorizontalscrollindicator=NO;//Set inner margin_mainscrollerview. Contentinset= Uiedgeinsetsmake (0,0, -,0);//Set offset, that is, start sliding to coordinates (x, y)_mainscrollerview. Contentoffset= Cgpointmake (0,0);//Set Spring effect_mainscrollerview. Bounces=YES;//Set spring effect in both vertical and horizontal directions, provided the bounces property must be Yes_mainscrollerview. Alwaysbouncevertical=YES; _mainscrollerview. Alwaysbouncehorizontal=YES;//Two methods of not allowing scrolling //_mainscrollerview.userinteractionenabled = NO; //_mainscrollerview.scrollenabled = NO;}#pragma custom Methods#pragma set up a carousel diagram-(void) setupbannerview{//Get the size of Bannerview cgsizeBannersize = _bannerview. Frame. Size; for(intI=0; i<5; i++) {//Calculate x Value CGFloatImageX = i * bannersize. Width;//Initialize the Carousel diagram Uiimageview*imageview = [[UiimageviewAlloc]initwithframe:cgrectmake (ImageX,0, bannersize. Width, bannersize. Height)];UIImage*image = [UIImageimagenamed:[NSStringstringwithformat:@"img_%02d", i+1]]; ImageView. Image= Image;//Add to Bannerview[_bannerview Addsubview:imageview]; }//Set the range of Scollerview sliding x and y_bannerview. Contentsize= Cgsizemake (5* Bannersize. Width,0);//Hide scroll bar_bannerview. Showsverticalscrollindicator=NO; _bannerview. Showshorizontalscrollindicator=NO;//Set Scollerview pagination effect by default, with each view as a paging standard_bannerview. pagingenabled=YES;}#pragma custom Methods#pragma set up a Carousel chart indicator-(void) setupbannerindication{//Total number of indicators_bannerindication. Numberofpages=5;//Current page indicator color_bannerindication. Currentpageindicatortintcolor= [UicolorOrangecolor];//non-current page indicator color_bannerindication. Pageindicatortintcolor= [UicolorWhitecolor];}#pragma custom Methods#pragma create a timer-(void) inittimer{_timer = [Nstimer scheduledtimerwithtimeinterval:3Target SelfSelector@selector(Startscroll) UserInfo:NilRepeatsYES];}#pragma custom Methods#pragma raise the priority of the timer to prevent the timer from not executing-(void) setuppriority{Nsrunloop *mainrunloop = [Nsrunloop mainrunloop]; [Mainrunloop Addtimer:_timer formode:nsrunloopcommonmodes];}#pragma scrolling delegates#pragma means that when scrollerview slows down, it is called when the hand is released.-(void) Scrollviewdidenddecelerating: (Uiscrollview*) scrollview{//Output current scrolling coordinates NSLog(@"Current coordinates:%@", Nsstringfromcgpoint (_bannerview. Contentoffset));//Calculates the current indicator's position according to the output current coordinates intPosition = _bannerview. Contentoffset. x/_bannerview. Frame. Size. Width;//Set Current indicator position_bannerindication. CurrentPage= position;}#pragma scrolling delegates#pragma called when Scrollerview starts dragging-(void) Scrollviewwillbegindragging: (Uiscrollview*) scrollview{//Stop Carousel[_timer invalidate];}#pragma scrolling delegates#pragma called when Scrollerview stops dragging-(void) Scrollviewdidenddragging: (Uiscrollview*) ScrollView Willdecelerate: (BOOL) decelerate{//Start Carousel[ SelfInittimer];}#pragma custom Methods#pragma turn on carousel, is a question of modifying values-(void) startscroll{//Get Contentoffset Cgpointoffset = _bannerview. Contentoffset;//Get current position NsintegerPosition = _bannerindication. CurrentPage;//Last photo if(Position = =4) {position =0; offset = Cgpointzero; }Else{//Modify ContentoffsetOffset. x+ = _bannerview. Frame. Size. Width;//Modify positionPosition + +; }//Set Value_bannerindication. CurrentPage= position; [_bannerview setcontentoffset:offset Animated:YES];}
Implementation ideas:
- Main interface
- Setting the ScrollView scrolling area
- Set ScrollView Other properties
- Carousel Diagram
- Tile horizontally based on the number of pictures
- Setting the ScrollView scrolling area
- Indicator set color and total
- Monitoring Events
- Carousel diagram should not be played when the carousel is being dragged by an artificial finger
- When the carousel is dragged by the end of the human finger, continue to play the carousel diagram
- When the carousel diagram is released by the human finger, the property value modification is calculated by calculating the position of the carousel.
- Timer
- Execute the @selector method at intervals to play the carousel diagram
- Elevate the timer priority so that it does not affect execution by other controls
SOURCE download
iOS Basics-Launchscreen, APPIcon, StatusBar, Uiscrollview, uipagecontrol through case studies