iOS Development-Project new features

Source: Internet
Author: User
Tags set background uikit

Practical tips for iOS development-handling of new project features pages

Practical tips for iOS development-handling of new project features pages

Description: This article mainly describes the most simple new feature interface (practical Uiscrollview to display multiple pictures of the carousel) in the project development.

code example:

Create a new special interface to deal with the controller, can be practical code can also be used xib, here practical pure code way, creating a controller Newfeatureviewcontroller.

Header File Code:

1//2//JMNewfeatureViewController.h3//45#import <UIKit/UIKit.h>67 typedefEnum: Nsinteger{ 9 newfeaturetypefromesetting, // go to the page from the Setup interface 10 newfeaturetypefromewelcom, // Enter 11 } Newfeaturetype; 12 13  @interface  Jmnewfeatureviewcontroller:uiviewcontroller14 15 Span style= "color: #000000;" > @property (nonatomic,assign) Newfeaturetype Newfeaturetype; 16 17  @end   

. m file Code:

1//2//Jmnewfeatureviewcontroller.m3//45#import"JMNewfeatureViewController.h"6#import"JMTabBarViewController.h"7#import"JMAboutTableViewController.h"89#define JMNEWFEATUREIMAGECOUNT 41011@interface Jmnewfeatureviewcontroller () <UIScrollViewDelegate>12@property (nonatomic, weak) Uipagecontrol *Pagecontrol;141516-(void) Setupscrollview;17-(void) Setuppagecontrol;18-(void) Setuplastimageview: (Uiimageview *) ImageView;19-(void) Setupstartbutton: (Uiimageview *) ImageView;2021st@end2223@implementationJmnewfeatureviewcontroller2425#pragma Mark---------------------26#pragma mark-cyclife2728-(void) Viewdidload29{30[Super Viewdidload];31[UIApplication Sharedapplication].statusbarhidden =YES;33[Self setupscrollview];//Add Uisrollview[Self Setuppagecontrol];//Add Pagecontrol36}3738#pragma Mark---------------------39#pragma mark-methods4041//Add Uisrollview42-(void) Setupscrollview43{44//Add UisrollviewUiscrollview *scrollview =[[Uiscrollview alloc] init];Scrollview.frame =Self.view.bounds;Scrollview.bounces =NO;ScrollView.Delegate =Self49[Self.view Addsubview:scrollview];5051//Add a pictureCGFloat Imagew =Scrollview.width;CGFloat Imageh =Scrollview.height;54for (int i =0; i<jmnewfeatureimagecount; i++) {55//Create UiimageviewUiimageview *imageview =[[Uiimageview alloc] init];NSString *name = [NSString stringWithFormat:@"Banner%d.jpg", I +1];Imageview.image =[UIImage Imagenamed:name];59[ScrollView Addsubview:imageview];6061//Set frameIMAGEVIEW.Y =0;Imageview.width =Imagew;Imageview.height =Imageh;imageview.x = i *Imagew;6667//Add a button to the last ImageView68if (i = = Jmnewfeatureimagecount-1) {69[Self setuplastimageview:imageview];70}71}7273//3. Set other propertiesScrollview.contentsize = Cgsizemake (Jmnewfeatureimagecount * Imagew,0);scrollview.pagingenabled =YES;Scrollview.showshorizontalscrollindicator =NO;Scrollview.backgroundcolor = Yycolor (246,246,246);78}7980//Add Pagecontrol81-(void) Setuppagecontrol82{83//Add PagecontrolUipagecontrol *pagecontrol =[[Uipagecontrol alloc] init];Pagecontrol.numberofpages =Jmnewfeatureimagecount;Pagecontrol.centerx = Self.view.width *0.5; Pagecontrol.centery = self.view.height-20; [Self.view Addsubview:pagecontrol]; 89 90//Set the color of the dots Self.pagecontrol = Pagecontrol; [Self ChangePageControlImage:self.pageControl]; 93} 94 95 96//set content in last Uiimageview-(void) Setuplastimageview: (Uiimageview *) ImageView 98 {Imageview.userinterac tionenabled = yes;100 101//Add Start button 102 [self setupstartbutton:imageview];103}104 105//Add Start button 106-(void) Setupstartbutton :(Uiimageview *) imageView107 {108//1. Add Start button 109 UIButton *startbutton = [[UIButton alloc] init];110 Imageview.userintera ctionenabled = yes;111 [ImageView addsubview:startbutton];112 113//2. Set background image [Startbutton setbackgroundimage:[ UIImage imagenamed:@ "Banner_button_moren.jpg"] forstate:uicontrolstatenormal];115 [Startbutton setBackgroundImage: [UIImage imagenamed:@ "Banner_button_dianji.jpg"] forstate:uicontrolstatehighlighted];116 117//3. Setting frame118 Startbutton.size = startbutton.currentbackgroundimage.size;119 Startbutton.centerx = self.view.width *0.5;120 startbutton.centery = self.view.height * 0.8;121 122//4. Set Text 123 [Startbutton settitle:@ "Experience Now" Forstate:uicontro lstatenormal];124 [Startbutton settitle:@ "" forstate:uicontrolstatehighlighted];125 [StartButton addTarget:self Action: @selector (start) forcontrolevents:uicontroleventtouchupinside];126}127 128 129//Change the dot style in Pagecontrol 130-( void) Changepagecontrolimage: (Uipagecontrol *) pageControl131 {static UIImage *imgcurrent = nil;133 static UIImage * Imgother = nil;134 static dispatch_once_t oncetoken;135 136 dispatch_once (&oncetoken, ^{137 imgCurrent = [UIImage imag enamed:@ "yuan_01"];138 imgother = [UIImage imagenamed:@ "Yuan1"];139}); 141 142 if (KSYSTEMVERSIONMORETHAN7) {143 [Pag] Econtrol setvalue:imgcurrent forkey:@ "_currentpageimage"];144 [Pagecontrol setvalue:imgother forKey:@ "_pageImage"]; 145} else {146 for (int i = 0;i < pagecontrol.numberofpages; i++) {147 Uiimageview *IMGV = [Pagecontrol.subviews objec tatindex:i];148 imgv.frame = CGRectMake (imgv.frame.origIn.x, IMGV.FRAME.ORIGIN.Y, 149 imgv.image = Pagecontrol.currentpage = = I? imgcurrent:imgother;150}151}152}153 154 #pragma mark---------------------155 #pragma mark-events156 157//Experience now 158 -(void) start159 {uiapplication Sharedapplication].statusbarhidden = no;161 162//Judgment Type 163 if (Self.newfeaturetype = = newfeaturetypefromewelcom) {164 Jmtabbarviewcontroller *TABVC = [[Jmtabbarviewcontroller alloc]init];165//Switch Controller 166 UIWindow *window = [uiapplication sharedapplication].keywindow;167 window.rootviewcontroller = tabVC;168}else 169 {170 1 [Self.navigationcontroller popviewcontrolleranimated:yes];172 [Self.navigationcontroller SetNavigationBarHidden : NO animated:no];173}174 175}176 177 #pragma mark-uiscrollviewdelegate178-(void) Scrollviewdidscroll: (UIScrollView *) scrollView179 {180//Get page number 181 cgfloat doublepage = scrollview.contentoffset.x/scrollview.width;182 int intpage = (int) (d Oublepage + 0.5); 183 184//Set page number 185 Self.pageControl.currentPage = intpage;186 [Self changepagecontrolimage:self.pagecontrol];187}188 189 @end 

Note the point:

The following method provides Pagecontrol with the current state and picture settings in the default state.

1//Change the dot style in Pagecontrol2-(void) Changepagecontrolimage: (Uipagecontrol *) Pagecontrol3{4static UIImage *imgcurrent =Nil5static UIImage *imgother =Nil6Staticdispatch_once_t Oncetoken;78 Dispatch_once (&oncetoken, ^{9 imgcurrent = [UIImage imagenamed:@"Yuan_01"];Ten imgother = [UIImage imagenamed:@"Yuan1"];11});121314If(KSYSTEMVERSIONMORETHAN7) {[Pagecontrol setvalue:imgcurrent Forkey:@"_currentpageimage"];[Pagecontrol setvalue:imgother Forkey:@"_pageimage"];17}Else {18 for (int i = 0;i < pagecontrol.numberofpages; I++) {19 uiimageview *imgv = [pagecontrol.subviews objectatindex:i];20 imgv.frame = CGRectMake (imgv.frame.origin.x, IMGV.FRAME.ORIGIN.Y, 20, 20); 21 imgv.image = Pagecontrol.currentpage = = I?  Imgcurrent:imgother; 22 }23 }24}            

In this case, the business logic of the new feature section is very simple and can be applied directly.

The effect of replacing pagecontrol with a practical picture is as follows:

  

iOS Development-Project new features

Related Article

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.